## FpiByteReader

FpiByteReader — Reads different integer, string and floating point types from a memory buffer

## Functions

FpiByteReader * | fpi_byte_reader_new ()
void | fpi_byte_reader_free ()
void | fpi_byte_reader_init ()
gboolean | fpi_byte_reader_peek_sub_reader ()
gboolean | fpi_byte_reader_get_sub_reader ()
gboolean | fpi_byte_reader_set_pos ()
guint | fpi_byte_reader_get_pos ()
guint | fpi_byte_reader_get_remaining ()
guint | fpi_byte_reader_get_size ()
gboolean | fpi_byte_reader_skip ()
gboolean | fpi_byte_reader_get_uint8 ()
gboolean | fpi_byte_reader_get_int8 ()
gboolean | fpi_byte_reader_peek_uint8 ()
gboolean | fpi_byte_reader_peek_int8 ()
gboolean | fpi_byte_reader_get_uint16_le ()
gboolean | fpi_byte_reader_get_int16_le ()
gboolean | fpi_byte_reader_peek_uint16_le ()
gboolean | fpi_byte_reader_peek_int16_le ()
gboolean | fpi_byte_reader_get_uint16_be ()
gboolean | fpi_byte_reader_get_int16_be ()
gboolean | fpi_byte_reader_peek_uint16_be ()
gboolean | fpi_byte_reader_peek_int16_be ()
gboolean | fpi_byte_reader_get_uint24_le ()
gboolean | fpi_byte_reader_get_int24_le ()
gboolean | fpi_byte_reader_peek_uint24_le ()
gboolean | fpi_byte_reader_peek_int24_le ()
gboolean | fpi_byte_reader_get_uint24_be ()
gboolean | fpi_byte_reader_get_int24_be ()
gboolean | fpi_byte_reader_peek_uint24_be ()
gboolean | fpi_byte_reader_peek_int24_be ()
gboolean | fpi_byte_reader_get_uint32_le ()
gboolean | fpi_byte_reader_get_int32_le ()
gboolean | fpi_byte_reader_peek_uint32_le ()
gboolean | fpi_byte_reader_peek_int32_le ()
gboolean | fpi_byte_reader_get_uint32_be ()
gboolean | fpi_byte_reader_get_int32_be ()
gboolean | fpi_byte_reader_peek_uint32_be ()
gboolean | fpi_byte_reader_peek_int32_be ()
gboolean | fpi_byte_reader_get_uint64_le ()
gboolean | fpi_byte_reader_get_int64_le ()
gboolean | fpi_byte_reader_peek_uint64_le ()
gboolean | fpi_byte_reader_peek_int64_le ()
gboolean | fpi_byte_reader_get_uint64_be ()
gboolean | fpi_byte_reader_get_int64_be ()
gboolean | fpi_byte_reader_peek_uint64_be ()
gboolean | fpi_byte_reader_peek_int64_be ()
gboolean | fpi_byte_reader_get_float32_le ()
gboolean | fpi_byte_reader_peek_float32_le ()
gboolean | fpi_byte_reader_get_float32_be ()
gboolean | fpi_byte_reader_peek_float32_be ()
gboolean | fpi_byte_reader_get_float64_le ()
gboolean | fpi_byte_reader_peek_float64_le ()
gboolean | fpi_byte_reader_get_float64_be ()
gboolean | fpi_byte_reader_peek_float64_be ()
gboolean | fpi_byte_reader_get_data ()
gboolean | fpi_byte_reader_peek_data ()
gboolean | fpi_byte_reader_dup_data ()
guint | fpi_byte_reader_masked_scan_uint32 ()
guint | fpi_byte_reader_masked_scan_uint32_peek ()
#define | fpi_byte_reader_skip_string()
gboolean | fpi_byte_reader_skip_string_utf8 ()
gboolean | fpi_byte_reader_skip_string_utf16 ()
gboolean | fpi_byte_reader_skip_string_utf32 ()
#define | fpi_byte_reader_peek_string()
gboolean | fpi_byte_reader_peek_string_utf8 ()
gboolean | fpi_byte_reader_get_string_utf8 ()
gboolean | fpi_byte_reader_dup_string_utf8 ()
gboolean | fpi_byte_reader_dup_string_utf16 ()
gboolean | fpi_byte_reader_dup_string_utf32 ()

## Types and Values

| FpiByteReader

## Description

FpiByteReader provides a byte reader that can read different integer and floating point types from a memory buffer. It provides functions for reading signed/unsigned, little/big endian integers of 8, 16, 24, 32 and 64 bits and functions for reading little/big endian floating points numbers of 32 and 64 bits. It also provides functions to read NUL-terminated strings in various character encodings.

## Functions

### fpi_byte_reader_new ()

    FpiByteReader *
    fpi_byte_reader_new (const guint8 *data,
                         guint size);

Create a new FpiByteReader instance, which will read from `data` .

Free-function: fpi_byte_reader_free

[skip]

#### Parameters

data | data from which the FpiByteReader should read. | [in][transfer none][array length=size]
size | Size of `data` in bytes |

#### Returns

a new FpiByteReader instance.

[transfer full]

### fpi_byte_reader_free ()

    void
    fpi_byte_reader_free (FpiByteReader *reader);

Frees a FpiByteReader instance, which was previously allocated by `fpi_byte_reader_new()`.

#### Parameters

reader | a FpiByteReader instance. | [in][transfer full]

### fpi_byte_reader_init ()

    void
    fpi_byte_reader_init (FpiByteReader *reader,
                          const guint8 *data,
                          guint size);

Initializes a FpiByteReader instance to read from `data` . This function can be called on already initialized instances.

#### Parameters

reader | a FpiByteReader instance |
data | data from which the FpiByteReader should read. | [in][transfer none][array length=size]
size | Size of `data` in bytes |

### fpi_byte_reader_peek_sub_reader ()

    gboolean
    fpi_byte_reader_peek_sub_reader (FpiByteReader *reader,
                                     FpiByteReader *sub_reader,
                                     guint size);

Initializes a FpiByteReader sub-reader instance to contain `size` bytes of data from the current position of `reader` . This is useful to read chunked formats and make sure that one doesn't read beyond the size of the sub-chunk.

Unlike `fpi_byte_reader_get_sub_reader()`, this function does not modify the current position of `reader` .

[skip]

#### Parameters

reader | an existing and initialized FpiByteReader instance |
sub_reader | a FpiByteReader instance to initialize as sub-reader |
size | size of `sub_reader` in bytes |

#### Returns

FALSE on error or if `reader` does not contain `size` more bytes from the current position, and otherwise TRUE

Since: 1.6

### fpi_byte_reader_get_sub_reader ()

    gboolean
    fpi_byte_reader_get_sub_reader (FpiByteReader *reader,
                                    FpiByteReader *sub_reader,
                                    guint size);

Initializes a FpiByteReader sub-reader instance to contain `size` bytes of data from the current position of `reader` . This is useful to read chunked formats and make sure that one doesn't read beyond the size of the sub-chunk.

Unlike `fpi_byte_reader_peek_sub_reader()`, this function also modifies the position of `reader` and moves it forward by `size` bytes.

[skip]

#### Parameters

reader | an existing and initialized FpiByteReader instance |
sub_reader | a FpiByteReader instance to initialize as sub-reader |
size | size of `sub_reader` in bytes |

#### Returns

FALSE on error or if `reader` does not contain `size` more bytes from the current position, and otherwise TRUE

Since: 1.6

### fpi_byte_reader_set_pos ()

    gboolean
    fpi_byte_reader_set_pos (FpiByteReader *reader,
                             guint pos);

Sets the new position of a FpiByteReader instance to `pos` in bytes.

#### Parameters

reader | a FpiByteReader instance |
pos | The new position in bytes |

#### Returns

`TRUE` if the position could be set successfully, `FALSE` otherwise.

### fpi_byte_reader_get_pos ()

    guint
    fpi_byte_reader_get_pos (const FpiByteReader *reader);

Returns the current position of a FpiByteReader instance in bytes.

#### Parameters

reader | a FpiByteReader instance |

#### Returns

The current position of `reader` in bytes.

### fpi_byte_reader_get_remaining ()

    guint
    fpi_byte_reader_get_remaining (const FpiByteReader *reader);

Returns the remaining number of bytes of a FpiByteReader instance.

#### Parameters

reader | a FpiByteReader instance |

#### Returns

The remaining number of bytes of `reader` instance.

### fpi_byte_reader_get_size ()

    guint
    fpi_byte_reader_get_size (const FpiByteReader *reader);

Returns the total number of bytes of a FpiByteReader instance.

#### Parameters

reader | a FpiByteReader instance |

#### Returns

The total number of bytes of `reader` instance.

### fpi_byte_reader_skip ()

    gboolean
    fpi_byte_reader_skip (FpiByteReader *reader,
                          guint nbytes);

Skips `nbytes` bytes of the FpiByteReader instance.

#### Parameters

reader | a FpiByteReader instance |
nbytes | the number of bytes to skip |

#### Returns

`TRUE` if `nbytes` bytes could be skipped, `FALSE` otherwise.

### fpi_byte_reader_get_uint8 ()

    gboolean
    fpi_byte_reader_get_uint8 (FpiByteReader *reader,
                               guint8 *val);

Read an unsigned 8 bit integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint8 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int8 ()

    gboolean
    fpi_byte_reader_get_int8 (FpiByteReader *reader,
                              gint8 *val);

Read a signed 8 bit integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint8 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint8 ()

    gboolean
    fpi_byte_reader_peek_uint8 (const FpiByteReader *reader,
                                guint8 *val);

Read an unsigned 8 bit integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint8 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int8 ()

    gboolean
    fpi_byte_reader_peek_int8 (const FpiByteReader *reader,
                               gint8 *val);

Read a signed 8 bit integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint8 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_uint16_le ()

    gboolean
    fpi_byte_reader_get_uint16_le (FpiByteReader *reader,
                                   guint16 *val);

Read an unsigned 16 bit little endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint16 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int16_le ()

    gboolean
    fpi_byte_reader_get_int16_le (FpiByteReader *reader,
                                  gint16 *val);

Read a signed 16 bit little endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint16 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint16_le ()

    gboolean
    fpi_byte_reader_peek_uint16_le (const FpiByteReader *reader,
                                    guint16 *val);

Read an unsigned 16 bit little endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint16 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int16_le ()

    gboolean
    fpi_byte_reader_peek_int16_le (const FpiByteReader *reader,
                                   gint16 *val);

Read a signed 16 bit little endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint16 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_uint16_be ()

    gboolean
    fpi_byte_reader_get_uint16_be (FpiByteReader *reader,
                                   guint16 *val);

Read an unsigned 16 bit big endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint16 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int16_be ()

    gboolean
    fpi_byte_reader_get_int16_be (FpiByteReader *reader,
                                  gint16 *val);

Read a signed 16 bit big endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint16 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint16_be ()

    gboolean
    fpi_byte_reader_peek_uint16_be (const FpiByteReader *reader,
                                    guint16 *val);

Read an unsigned 16 bit big endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint16 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int16_be ()

    gboolean
    fpi_byte_reader_peek_int16_be (const FpiByteReader *reader,
                                   gint16 *val);

Read a signed 16 bit big endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint16 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_uint24_le ()

    gboolean
    fpi_byte_reader_get_uint24_le (FpiByteReader *reader,
                                   guint32 *val);

Read an unsigned 24 bit little endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int24_le ()

    gboolean
    fpi_byte_reader_get_int24_le (FpiByteReader *reader,
                                  gint32 *val);

Read a signed 24 bit little endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint24_le ()

    gboolean
    fpi_byte_reader_peek_uint24_le (const FpiByteReader *reader,
                                    guint32 *val);

Read an unsigned 24 bit little endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int24_le ()

    gboolean
    fpi_byte_reader_peek_int24_le (const FpiByteReader *reader,
                                   gint32 *val);

Read a signed 24 bit little endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_uint24_be ()

    gboolean
    fpi_byte_reader_get_uint24_be (FpiByteReader *reader,
                                   guint32 *val);

Read an unsigned 24 bit big endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int24_be ()

    gboolean
    fpi_byte_reader_get_int24_be (FpiByteReader *reader,
                                  gint32 *val);

Read a signed 24 bit big endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint24_be ()

    gboolean
    fpi_byte_reader_peek_uint24_be (const FpiByteReader *reader,
                                    guint32 *val);

Read an unsigned 24 bit big endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int24_be ()

    gboolean
    fpi_byte_reader_peek_int24_be (const FpiByteReader *reader,
                                   gint32 *val);

Read a signed 24 bit big endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_uint32_le ()

    gboolean
    fpi_byte_reader_get_uint32_le (FpiByteReader *reader,
                                   guint32 *val);

Read an unsigned 32 bit little endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int32_le ()

    gboolean
    fpi_byte_reader_get_int32_le (FpiByteReader *reader,
                                  gint32 *val);

Read a signed 32 bit little endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint32_le ()

    gboolean
    fpi_byte_reader_peek_uint32_le (const FpiByteReader *reader,
                                    guint32 *val);

Read an unsigned 32 bit little endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int32_le ()

    gboolean
    fpi_byte_reader_peek_int32_le (const FpiByteReader *reader,
                                   gint32 *val);

Read a signed 32 bit little endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_uint32_be ()

    gboolean
    fpi_byte_reader_get_uint32_be (FpiByteReader *reader,
                                   guint32 *val);

Read an unsigned 32 bit big endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int32_be ()

    gboolean
    fpi_byte_reader_get_int32_be (FpiByteReader *reader,
                                  gint32 *val);

Read a signed 32 bit big endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint32_be ()

    gboolean
    fpi_byte_reader_peek_uint32_be (const FpiByteReader *reader,
                                    guint32 *val);

Read an unsigned 32 bit big endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int32_be ()

    gboolean
    fpi_byte_reader_peek_int32_be (const FpiByteReader *reader,
                                   gint32 *val);

Read a signed 32 bit big endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint32 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_uint64_le ()

    gboolean
    fpi_byte_reader_get_uint64_le (FpiByteReader *reader,
                                   guint64 *val);

Read an unsigned 64 bit little endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint64 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int64_le ()

    gboolean
    fpi_byte_reader_get_int64_le (FpiByteReader *reader,
                                  gint64 *val);

Read a signed 64 bit little endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint64 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint64_le ()

    gboolean
    fpi_byte_reader_peek_uint64_le (const FpiByteReader *reader,
                                    guint64 *val);

Read an unsigned 64 bit little endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint64 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int64_le ()

    gboolean
    fpi_byte_reader_peek_int64_le (const FpiByteReader *reader,
                                   gint64 *val);

Read a signed 64 bit little endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint64 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_uint64_be ()

    gboolean
    fpi_byte_reader_get_uint64_be (FpiByteReader *reader,
                                   guint64 *val);

Read an unsigned 64 bit big endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint64 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_int64_be ()

    gboolean
    fpi_byte_reader_get_int64_be (FpiByteReader *reader,
                                  gint64 *val);

Read a signed 64 bit big endian integer into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint64 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_uint64_be ()

    gboolean
    fpi_byte_reader_peek_uint64_be (const FpiByteReader *reader,
                                    guint64 *val);

Read an unsigned 64 bit big endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a guint64 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_int64_be ()

    gboolean
    fpi_byte_reader_peek_int64_be (const FpiByteReader *reader,
                                   gint64 *val);

Read a signed 64 bit big endian integer into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gint64 to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_float32_le ()

    gboolean
    fpi_byte_reader_get_float32_le (FpiByteReader *reader,
                                    gfloat *val);

Read a 32 bit little endian floating point value into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gfloat to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_float32_le ()

    gboolean
    fpi_byte_reader_peek_float32_le (const FpiByteReader *reader,
                                     gfloat *val);

Read a 32 bit little endian floating point value into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gfloat to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_float32_be ()

    gboolean
    fpi_byte_reader_get_float32_be (FpiByteReader *reader,
                                    gfloat *val);

Read a 32 bit big endian floating point value into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gfloat to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_float32_be ()

    gboolean
    fpi_byte_reader_peek_float32_be (const FpiByteReader *reader,
                                     gfloat *val);

Read a 32 bit big endian floating point value into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gfloat to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_float64_le ()

    gboolean
    fpi_byte_reader_get_float64_le (FpiByteReader *reader,
                                    gdouble *val);

Read a 64 bit little endian floating point value into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gdouble to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_float64_le ()

    gboolean
    fpi_byte_reader_peek_float64_le (const FpiByteReader *reader,
                                     gdouble *val);

Read a 64 bit little endian floating point value into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gdouble to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_float64_be ()

    gboolean
    fpi_byte_reader_get_float64_be (FpiByteReader *reader,
                                    gdouble *val);

Read a 64 bit big endian floating point value into `val` and update the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gdouble to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_float64_be ()

    gboolean
    fpi_byte_reader_peek_float64_be (const FpiByteReader *reader,
                                     gdouble *val);

Read a 64 bit big endian floating point value into `val` but keep the current position.

#### Parameters

reader | a FpiByteReader instance |
val | Pointer to a gdouble to store the result. | [out]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_get_data ()

    gboolean
    fpi_byte_reader_get_data (FpiByteReader *reader,
                              guint size,
                              const guint8 **val);

Returns a constant pointer to the current data position if at least `size` bytes are left and updates the current position.

#### Parameters

reader | a FpiByteReader instance |
size | Size in bytes |
val | address of a guint8 pointer variable in which to store the result. | [out][transfer none][array length=size]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_peek_data ()

    gboolean
    fpi_byte_reader_peek_data (const FpiByteReader *reader,
                               guint size,
                               const guint8 **val);

Returns a constant pointer to the current data position if at least `size` bytes are left and keeps the current position.

#### Parameters

reader | a FpiByteReader instance |
size | Size in bytes |
val | address of a guint8 pointer variable in which to store the result. | [out][transfer none][array length=size]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_dup_data ()

    gboolean
    fpi_byte_reader_dup_data (FpiByteReader *reader,
                              guint size,
                              guint8 **val);

Free-function: g_free

Returns a newly-allocated copy of the current data position if at least `size` bytes are left and updates the current position. Free with `g_free()` when no longer needed.

#### Parameters

reader | a FpiByteReader instance |
size | Size in bytes |
val | address of a guint8 pointer variable in which to store the result. | [out][transfer full][array length=size]

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### fpi_byte_reader_masked_scan_uint32 ()

    guint
    fpi_byte_reader_masked_scan_uint32 (const FpiByteReader *reader,
                                        guint32 mask,
                                        guint32 pattern,
                                        guint offset,
                                        guint size);

Scan for pattern `pattern` with applied mask `mask` in the byte reader data, starting from offset `offset` relative to the current position.

The bytes in `pattern` and `mask` are interpreted left-to-right, regardless of endianness. All four bytes of the pattern must be present in the byte reader data for it to match, even if the first or last bytes are masked out.

It is an error to call this function without making sure that there is enough data (offset+size bytes) in the byte reader.

#### Parameters

reader | a FpiByteReader |
mask | mask to apply to data before matching against `pattern` |
pattern | pattern to match (after mask is applied) |
offset | offset from which to start scanning, relative to the current position |
size | number of bytes to scan from offset |

#### Returns

offset of the first match, or -1 if no match was found.

Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    // Assume the reader contains 0x00 0x01 0x02 ... 0xfe 0xff
    fpi_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x00010203, 0, 256);
    // -> returns 0
    fpi_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x00010203, 1, 255);
    // -> returns -1
    fpi_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x01020304, 1, 255);
    // -> returns 1
    fpi_byte_reader_masked_scan_uint32 (reader, 0xffff, 0x0001, 0, 256);
    // -> returns -1
    fpi_byte_reader_masked_scan_uint32 (reader, 0xffff, 0x0203, 0, 256);
    // -> returns 0
    fpi_byte_reader_masked_scan_uint32 (reader, 0xffff0000, 0x02030000, 0, 256);
    // -> returns 2
    fpi_byte_reader_masked_scan_uint32 (reader, 0xffff0000, 0x02030000, 0, 4);
    // -> returns -1

### fpi_byte_reader_masked_scan_uint32_peek ()

    guint
    fpi_byte_reader_masked_scan_uint32_peek
                                   (const FpiByteReader *reader,
                                    guint32 mask,
                                    guint32 pattern,
                                    guint offset,
                                    guint size,
                                    guint32 *value);

Scan for pattern `pattern` with applied mask `mask` in the byte reader data, starting from offset `offset` relative to the current position.

The bytes in `pattern` and `mask` are interpreted left-to-right, regardless of endianness. All four bytes of the pattern must be present in the byte reader data for it to match, even if the first or last bytes are masked out.

It is an error to call this function without making sure that there is enough data (offset+size bytes) in the byte reader.

#### Parameters

reader | a FpiByteReader |
mask | mask to apply to data before matching against `pattern` |
pattern | pattern to match (after mask is applied) |
offset | offset from which to start scanning, relative to the current position |
size | number of bytes to scan from offset |
value | pointer to uint32 to return matching data. | [out]

#### Returns

offset of the first match, or -1 if no match was found.

Since: 1.6

### fpi_byte_reader_skip_string()

    #define             fpi_byte_reader_skip_string(reader)

Skips a NUL-terminated string in the FpiByteReader instance, advancing the current position to the byte after the string. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc.

This function will fail if no NUL-terminator was found in in the data.

#### Parameters

reader | a FpiByteReader instance |

#### Returns

`TRUE` if a string could be skipped, `FALSE` otherwise.

### fpi_byte_reader_skip_string_utf8 ()

    gboolean
    fpi_byte_reader_skip_string_utf8 (FpiByteReader *reader);

Skips a NUL-terminated string in the FpiByteReader instance, advancing the current position to the byte after the string. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc. No input checking for valid UTF-8 is done.

This function will fail if no NUL-terminator was found in in the data.

#### Parameters

reader | a FpiByteReader instance |

#### Returns

`TRUE` if a string could be skipped, `FALSE` otherwise.

### fpi_byte_reader_skip_string_utf16 ()

    gboolean
    fpi_byte_reader_skip_string_utf16 (FpiByteReader *reader);

Skips a NUL-terminated UTF-16 string in the FpiByteReader instance, advancing the current position to the byte after the string.

No input checking for valid UTF-16 is done.

This function will fail if no NUL-terminator was found in in the data.

#### Parameters

reader | a FpiByteReader instance |

#### Returns

`TRUE` if a string could be skipped, `FALSE` otherwise.

### fpi_byte_reader_skip_string_utf32 ()

    gboolean
    fpi_byte_reader_skip_string_utf32 (FpiByteReader *reader);

Skips a NUL-terminated UTF-32 string in the FpiByteReader instance, advancing the current position to the byte after the string.

No input checking for valid UTF-32 is done.

This function will fail if no NUL-terminator was found in in the data.

#### Parameters

reader | a FpiByteReader instance |

#### Returns

`TRUE` if a string could be skipped, `FALSE` otherwise.

### fpi_byte_reader_peek_string()

    #define             fpi_byte_reader_peek_string(reader,str)

Returns a constant pointer to the current data position if there is a NUL-terminated string in the data (this could be just a NUL terminator). The current position will be maintained. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc.

This function will fail if no NUL-terminator was found in in the data.

#### Parameters

reader | a FpiByteReader instance |
str | address of a gchar pointer variable in which to store the result. | [out][transfer none][array zero-terminated=1]

#### Returns

`TRUE` if a string could be skipped, `FALSE` otherwise.

### fpi_byte_reader_peek_string_utf8 ()

    gboolean
    fpi_byte_reader_peek_string_utf8 (const FpiByteReader *reader,
                                      const gchar **str);

Returns a constant pointer to the current data position if there is a NUL-terminated string in the data (this could be just a NUL terminator). The current position will be maintained. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc.

No input checking for valid UTF-8 is done.

This function will fail if no NUL-terminator was found in in the data.

#### Parameters

reader | a FpiByteReader instance |
str | address of a gchar pointer variable in which to store the result. | [out][transfer none][array zero-terminated=1]

#### Returns

`TRUE` if a string could be skipped, `FALSE` otherwise.

### fpi_byte_reader_get_string_utf8 ()

    gboolean
    fpi_byte_reader_get_string_utf8 (FpiByteReader *reader,
                                     const gchar **str);

Returns a constant pointer to the current data position if there is a NUL-terminated string in the data (this could be just a NUL terminator), advancing the current position to the byte after the string. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc.

No input checking for valid UTF-8 is done.

This function will fail if no NUL-terminator was found in in the data.

#### Parameters

reader | a FpiByteReader instance |
str | address of a gchar pointer variable in which to store the result. | [out][transfer none][array zero-terminated=1]

#### Returns

`TRUE` if a string could be found, `FALSE` otherwise.

### fpi_byte_reader_dup_string_utf8 ()

    gboolean
    fpi_byte_reader_dup_string_utf8 (FpiByteReader *reader,
                                     gchar **str);

Free-function: g_free

FIXME:Reads (copies) a NUL-terminated string in the FpiByteReader instance, advancing the current position to the byte after the string. This will work for any NUL-terminated string with a character width of 8 bits, so ASCII, UTF-8, ISO-8859-N etc. No input checking for valid UTF-8 is done.

This function will fail if no NUL-terminator was found in in the data.

#### Parameters

reader | a FpiByteReader instance |
str | address of a gchar pointer variable in which to store the result. | [out][transfer full][array zero-terminated=1]

#### Returns

`TRUE` if a string could be read into `str` , `FALSE` otherwise. The string put into `str` must be freed with `g_free()` when no longer needed.

### fpi_byte_reader_dup_string_utf16 ()

    gboolean
    fpi_byte_reader_dup_string_utf16 (FpiByteReader *reader,
                                      guint16 **str);

Free-function: g_free

Returns a newly-allocated copy of the current data position if there is a NUL-terminated UTF-16 string in the data (this could be an empty string as well), and advances the current position.

No input checking for valid UTF-16 is done. This function is endianness agnostic - you should not assume the UTF-16 characters are in host endianness.

This function will fail if no NUL-terminator was found in in the data.

Note: there is no peek or get variant of this function to ensure correct byte alignment of the UTF-16 string.

#### Parameters

reader | a FpiByteReader instance |
str | address of a guint16 pointer variable in which to store the result. | [out][transfer full][array zero-terminated=1]

#### Returns

`TRUE` if a string could be read, `FALSE` otherwise. The string put into `str` must be freed with `g_free()` when no longer needed.

### fpi_byte_reader_dup_string_utf32 ()

    gboolean
    fpi_byte_reader_dup_string_utf32 (FpiByteReader *reader,
                                      guint32 **str);

Free-function: g_free

Returns a newly-allocated copy of the current data position if there is a NUL-terminated UTF-32 string in the data (this could be an empty string as well), and advances the current position.

No input checking for valid UTF-32 is done. This function is endianness agnostic - you should not assume the UTF-32 characters are in host endianness.

This function will fail if no NUL-terminator was found in in the data.

Note: there is no peek or get variant of this function to ensure correct byte alignment of the UTF-32 string.

#### Parameters

reader | a FpiByteReader instance |
str | address of a guint32 pointer variable in which to store the result. | [out][transfer full][array zero-terminated=1]

#### Returns

`TRUE` if a string could be read, `FALSE` otherwise. The string put into `str` must be freed with `g_free()` when no longer needed.

## Types and Values

### FpiByteReader

    typedef struct {
      const guint8 *data;
      guint size;

      guint byte;  /* Byte position */
    } FpiByteReader;

A byte reader instance.

#### Members

const guint8 *`data`; | Data from which the bit reader will read. | [array length=size]
guint `size`; | Size of `data` in bytes |
guint `byte`; | Current byte position |