Banjo API 0.0.1
C99 game development API
Loading...
Searching...
No Matches
Data Stream

Macros

#define bj_stream_read_t(stream, type, buffer)
#define bj_stream_skip_t(stream, type)

Typedefs

typedef struct bj_stream_t bj_stream

Enumerations

enum  bj_seek_origin { BJ_SEEK_BEGIN = 0x00 , BJ_SEEK_CURRENT = 0x01 , BJ_SEEK_END = 0x02 }

Functions

bj_streambj_allocate_stream (void)
bj_streambj_open_stream_read (const void *p_data, size_t length)
bj_streambj_open_stream_file (const char *p_path, bj_error **p_error)
void bj_close_stream (bj_stream *p_stream)
size_t bj_read_stream (bj_stream *p_stream, void *p_dest, size_t count)
size_t bj_get_stream_length (bj_stream *p_stream)
size_t bj_seek_stream (bj_stream *p_stream, ptrdiff_t position, bj_seek_origin from)
size_t bj_tell_stream (bj_stream *p_stream)

Detailed Description

Macro Definition Documentation

◆ bj_stream_read_t

#define bj_stream_read_t ( stream,
type,
buffer )
Value:
bj_read_stream(stream, buffer, sizeof(type))
size_t bj_read_stream(bj_stream *p_stream, void *p_dest, size_t count)
Reads data from the stream into a destination buffer.

Reads data of a specified type from the stream into a buffer.

Parameters
streamPointer to the stream instance.
typeData type to read.
bufferPointer to the buffer to store the read data.

◆ bj_stream_skip_t

#define bj_stream_skip_t ( stream,
type )
Value:
bj_read_stream(stream, 0, sizeof(type))

Skips reading data of a specified type from the stream.

Parameters
streamPointer to the stream instance.
typeData type to skip.

Typedef Documentation

◆ bj_stream

typedef struct bj_stream_t bj_stream

Structure representing a stream of data.

Typedef for the bj_stream_t struct

Enumeration Type Documentation

◆ bj_seek_origin

Position in a bj_stream to use for origin.

Enumerator
BJ_SEEK_BEGIN 

The beginning of the stream.

BJ_SEEK_CURRENT 

The current position of the stream.

BJ_SEEK_END 

The end of the stream.

Function Documentation

◆ bj_allocate_stream()

bj_stream * bj_allocate_stream ( void )

Allocate a new bj_stream object.

Returns
A pointer to a new bj_stream
Memory Management

The object pointed by the returned value must be deleted using bj_free.

◆ bj_close_stream()

void bj_close_stream ( bj_stream * p_stream)

Deletes a bj_stream object and releases associated memory.

Parameters
p_streamPointer to the bj_stream object to delete.

◆ bj_get_stream_length()

size_t bj_get_stream_length ( bj_stream * p_stream)

Get the size of the stream.

Parameters
p_streamPointer to the stream instance.
Returns
The size of the stream, in bytes

◆ bj_open_stream_file()

bj_stream * bj_open_stream_file ( const char * p_path,
bj_error ** p_error )

Creates a new bj_stream for reading from a file.

Parameters
p_pathThe file path to open
p_errorOptional error object
Returns
A pointer to an error object

The file memory is entirely copied to internal memory buffer.

◆ bj_open_stream_read()

bj_stream * bj_open_stream_read ( const void * p_data,
size_t length )

Creates a new bj_stream for reading from a memory buffer.

Parameters
p_dataPointer to the data buffer.
lengthLength of the data buffer in bytes.
Returns
A pointer to the newly created bj_stream object.

◆ bj_read_stream()

size_t bj_read_stream ( bj_stream * p_stream,
void * p_dest,
size_t count )

Reads data from the stream into a destination buffer.

Parameters
p_streamPointer to the stream instance.
p_destPointer to the destination buffer.
countNumber of bytes to read.
Returns
Number of bytes actually read.

The function advances the stream position by count bytes. If fewer bytes than count are read, the end of the stream is reached.

Memory Safety

This function does not perform any memory bounds checking. It is the caller's responsibility to ensure p_dest has enough space to hold count bytes.

◆ bj_seek_stream()

size_t bj_seek_stream ( bj_stream * p_stream,
ptrdiff_t position,
bj_seek_origin from )

Seeks to a new position in the stream relative to a specified origin.

Parameters
p_streamPointer to the stream instance.
positionOffset for the new position.
fromOrigin relative to which the position should be calculated.
Returns
The new position within the stream after seeking.

The function clamps the new position to stay within the valid range of the stream, from 0 to the length of the stream.

◆ bj_tell_stream()

size_t bj_tell_stream ( bj_stream * p_stream)

Returns the current position of the cursor in the stream.

Parameters
p_streamPointer to the stream instance.
Returns
The current position within the stream.