Parser for binary files. More...
#include <stdlib.h>#include <stdint.h>#include <string.h>#include <time.h>#include "binaryparser/version.h"Go to the source code of this file.
Data Structures | |
| class | bparser_bool_funcs_t |
| A small struct that keeps track of the handler function and the actual function to run, as specified by bparser_read_bool_and_run. More... | |
| class | bparser_seek_data_t |
| A small struct keeping track of the parsers position in the file. More... | |
| class | bparser_read_t |
| Describes a read rule. More... | |
| class | bparser_data_t |
| Stores parsed data. More... | |
| class | bparser_parser_t |
| The parser. More... | |
Macros | |
| #define | BPARSER_UINT8 |
| Enum value for an uint8 value. | |
| #define | BPARSER_UINT16 |
| Enum value for an uint16 value. | |
| #define | BPARSER_UINT24 |
| Enum value for an uint24 value. | |
| #define | BPARSER_UINT32 |
| Enum value for an uint32 value. | |
| #define | BPARSER_UINT64 |
| Enum value for an uint64 value. | |
| #define | BPARSER_UINT128 |
| Enum value for an uint128 value. | |
| #define | BPARSER_INT8 |
| Enum value for an int8 value. | |
| #define | BPARSER_INT16 |
| Enum value for an int16 value. | |
| #define | BPARSER_INT24 |
| Enum value for an int24 value. | |
| #define | BPARSER_INT32 |
| Enum value for an int32 value. | |
| #define | BPARSER_INT64 |
| Enum value for an int64 value. | |
| #define | BPARSER_INT128 |
| Enum value for an int128 value. | |
| #define | BPARSER_STR |
| Enum value for a string datatype. | |
| #define | BPARSER_N_BYTES |
| Enum value for a byte array. | |
| #define | BPARSER_FIXED_STR |
| Enum value for a string datatype of a set length. | |
| #define | BPARSER_FLOAT |
| Enum value for a float datatype. | |
| #define | BPARSER_DOUBLE |
| Enum value for a double datatype. | |
| #define | BPARSER_UNIX_TIME |
| Enum value for the unix timestamp. | |
| #define | BPARSER_UNICODE_FROM_UTF8_STR |
| Enum value for reading unicode codepoints from a null-terminated UTF8 string. | |
| #define | BPARSER_UNICODE_FROM_UTF8_F_STR |
| Enum value for reading unicode codepoints from a fixed length UTF8 string. | |
| #define | BPARSER_UTF8_STR |
| Enum value for reading a null-terminated UTF8 string. | |
| #define | BPARSER_UTF8_F_STR |
| Enum value for reading a fixed length UTF8 string. | |
| #define | BPARSER_BOOLS |
| Enum value for a boolean array. | |
| #define | BPARSER_BOOL_RUN |
| Enum value for reading a boolean and running a function if it's true. | |
| #define | BPARSER_SEEK_TO |
| Enum value used to specify seeking to a certain position. | |
| #define | BPARSER_SEEK_FORWARD |
| Enum value used to specify seeking forward. | |
| #define | BPARSER_SEEK_BACKWARD |
| Enum value used to specify seeking backward. | |
| #define | BPARSER_SEEK_FROM_END |
| Enum value used to specify seeking from the end. | |
| #define | BPARSER_NO_SEEK |
| Internal value, don't use. | |
| #define | BPARSER_RO_ARRAY_ERROR |
| Error code for when reallocating the RO array failed. | |
| #define | BPARSER_MALLOC_ERROR |
| Returned when malloc (or the user-defined function replacing malloc) fails. | |
| #define | BPARSER_NO_FUNC_PASSED |
| Error code for when bparser_read_bytes_and_run or bparser_read_bool_and_run have no function given. | |
| #define | BPARSER_SPRINTF_ERROR |
| Error code for when sprintf fails. | |
| #define | BPARSER_BACKWARD_SEEK_ERROR |
| Error code for when seeking backwards beyond the beginning of the file. | |
| #define | BPARSER_SEEK_FROM_END_ERROR |
| Error code for when seeking from the end goes beyond the beginning of the file. | |
| #define | BPARSER_EOF_ERROR |
| Error code for when the parser reaches EOF. | |
| #define | BPARSER_CALLOC_ERROR |
| Error code for when calloc fails. | |
| #define | BPARSER_UNKNOWN_ENDIAN |
| Error code for when the parser encounters an unknown endianess. | |
| #define | BPARSER_UNKNOWN_READ_TYPE |
| Error code for when the parser encounters an unknown data type. | |
| #define | BPARSER_FOPEN_ERROR |
| Error code for when fopen errors out in bparser_fread. | |
| #define | BPARSER_FSEEK_ERROR |
| Error code for when fseek errors out in bparser_fread. | |
| #define | BPARSER_FTELL_ERROR |
| Error code for when ftell errors out in bparser_fread. | |
| #define | BPARSER_FREAD_EOF_ERROR |
| Error code for when fread errors out on an unexpected EOF in bparser_fread. | |
| #define | BPARSER_SEEK_ERROR |
| Error code for when an invalid seeking mode is specified to bparser_seek. | |
| #define | BPARSER_BAD_INTEGRAL_TYPE |
| Error code for bparser_read_integral was given a bad integral type. | |
| #define | BPARSER_BAD_REALLOC_METHOD |
| Error code for when bparser_parser_set_realloc_method is fed a bad / unknown realloc method. | |
| #define | BPARSER_REALLOC_FACTOR_TOO_SMALL |
| Error code for when bparser_parser_set_realloc_method N arg is smaller than 1. | |
| #define | BPARSER_RENAME_NOT_FOUND |
| Error code for when bparser_rename cannot find a data object of name Src. | |
| #define | BPARSER_PDC_INIT_ERROR |
| Error code for when bparser_init fails from within bparser_parser_deep_copy. | |
| #define | BPARSER_PDC_RO_COPY_ERROR |
| Error code for when bparser_read_order_deep_copy fails from within bparser_parser_deep_copy. | |
| #define | BPARSER_NULL_NAME |
| Error code for when a bparser_read_* function recieves a NULL pointer for its' Name argument. | |
| #define | BPARSER_SHORT_NAME |
| Error code for when a bparser_read_* function recieves a string shorter than 1 char for its' Name argument. | |
| #define | BPARSER_NO_PARSER |
| Error code for when a function that changes or reads a parser instance, has no parser instance specified. | |
| #define | BPARSER_ZERO_LENGTH |
| Error code for when an argument passed to a function is not of satisfactory length. | |
| #define | BPARSER_NAME_IS_NOT_UNIQUE |
| Error code for when a name of a read rule that is about to be created is not unique. | |
| #define | BPARSER_NO_BOOLS_TO_READ |
| Error code for _bparser_bool's argument A is equal to zero. | |
| #define | BPARSER_PDC_DATA_COPY_ERROR |
| Error code for when bparser_data_deep_copy fails from within bparser_parser_deep_copy. | |
| #define | BPARSER_FREAD_ERROR |
| Error code for when fread() errored out. | |
| #define | BPARSER_FREAD_UNKNOWN_ERROR |
| Error code for when fread() errored out with an unknown reason. | |
| #define | BPARSER_NULL_DATA |
| Error code for when bparser_read's Data arg is null. | |
| #define | BPARSER_NOTHING_TO_PARSE |
| Error code for when bparser_read's Size arg is zero. | |
| #define | BPARSER_EMPTY_FILE |
| Error code for when bparser_fread tries to read an empty file. | |
| #define | BPARSER_BAD_OVERRIDE |
| Error code for when bparser_set_override has been specified with an unknown override method. | |
| #define | BPARSER_OK(expr) |
| Use this on any bparser_ function that can return an error code to check if it didn't error out. | |
| #define | BPARSER_LITTLE_ENDIAN |
| Used internally, tells us to read an integer in little endian mode. | |
| #define | BPARSER_BIG_ENDIAN |
| Used internally, tells us to read an integer in big endian mode. | |
| #define | BPARSER_DEFAULT_ENDIAN |
| Use with bparser_read_integral, to use the currently set endianess of the parser. | |
| #define | BPARSER_REALLOC_METHOD_PLUS |
| Tells the parser to calculate new size to realloc as: new_size = old_size + N. | |
| #define | BPARSER_REALLOC_METHOD_MULT |
| Tells the parser to calculate new size to realloc as: new_size = old_size * N a.k.a. default behaviour. | |
| #define | bparser_read_uint8(Parser, Name) |
| Shortcut for reading an uint8. | |
| #define | bparser_read_int8(Parser, Name) |
| Shortcut for reading an int8. | |
| #define | bparser_read_uint16(Parser, Name) |
| Shortcut for reading an uint16. | |
| #define | bparser_read_int16(Parser, Name) |
| Shortcut for reading an int16. | |
| #define | bparser_read_uint24(Parser, Name) |
| Shortcut for reading an uint24. | |
| #define | bparser_read_int24(Parser, Name) |
| Shortcut for reading an int24. | |
| #define | bparser_read_uint32(Parser, Name) |
| Shortcut for reading an uint32. | |
| #define | bparser_read_int32(Parser, Name) |
| Shortcut for reading an int32. | |
| #define | bparser_read_uint64(Parser, Name) |
| Shortcut for reading an uint64. | |
| #define | bparser_read_int64(Parser, Name) |
| Shortcut for reading an int64. | |
| #define | bparser_read_uint128(Parser, Name) |
| Shortcut for reading an uint128. | |
| #define | bparser_read_int128(Parser, Name) |
| Shortcut for reading an int128. | |
| #define | BPARSER_BYTES_F_ARGS |
| Shortcut for argument list of bparser_bytes_f function. You can use it while making your own. | |
| #define | BPARSER_BYTES_SEQ_F_ARGS |
| Shortcut for argument list of bparser_bytes_seq_f function. You can use it while making your own. | |
| #define | BPARSER_OVERRIDE_ERROR |
| When a read rule has a name that is already used by some other, error out. | |
| #define | BPARSER_OVERRIDE_TRUE |
| When a read rule has a name that is already used by some other, override it. | |
| #define | BPARSER_OVERRIDE_SKIP |
| When a read rule has a name that is already used by some other, simply do not create it. | |
| #define | BPARSER_OVERRIDE_DO_NOTHING |
| When a read rule has a name that is already used by some other, the library does not care. Use wisely. | |
| #define | BPARSER_BOOL_HANDLER_F_ARGS |
| Shortcut for argument list of bparser_bool_handler_f function. You can use it while making your own. | |
| #define | BPARSER_BOOL_F_ARGS |
| Shortcut for argument list of bparser_bool_f function. You can use it while making your own. | |
Typedefs | |
| typedef void(* | bparser_bytes_f) (BPARSER_BYTES_F_ARGS) |
| Shortcut for the function to run as specified by bparser_read_bytes_and_run. | |
| typedef void(* | bparser_bytes_seq_f) (BPARSER_BYTES_SEQ_F_ARGS) |
| Shortcut for the function to run as specified by bparser_read_bytes_and_run_sequential. | |
| typedef char(* | bparser_bool_handler_f) (BPARSER_BOOL_HANDLER_F_ARGS) |
| Shortcut for handler function that controls whether bparser_bool_f runs. | |
| typedef void(* | bparser_bool_f) (BPARSER_BOOL_F_ARGS) |
| Shortcut for the function that runs as specified by bparser_read_bool_and_run. | |
| typedef void *(* | bparser_calloc_like_f) (size_t num, size_t size) |
| Shortcut for a custom callback for a calloc-like function. | |
| typedef void(* | bparser_free_like_f) (void *ptr) |
| Shortcut for a custom callback for a free-like function. | |
| typedef void *(* | bparser_malloc_like_f) (size_t size) |
| Shortcut for a custom callback for a malloc-like function. | |
| typedef void *(* | bparser_realloc_like_f) (void *ptr, size_t size) |
| Shortcut for a custom callback for a realloc-like function. | |
Functions | |
| bparser_parser_t * | bparser_init (bparser_malloc_like_f MallocLikeFunc, bparser_calloc_like_f CallocLikeFunc, bparser_realloc_like_f ReallocLikeFunc, bparser_free_like_f FreeLikeFunc) |
| Create a new parser instance. | |
| void | bparser_destroy (bparser_parser_t *MParser) |
| Destroy a parser instance. | |
| void | bparser_shallow_destroy (bparser_parser_t *MParser) |
| Destroys a shallow copy of a parser instance. | |
| void * | bparser_set_malloc (bparser_parser_t *MParser, bparser_malloc_like_f Malloc) |
| Override the malloc function used internally by the parser. | |
| void * | bparser_set_calloc (bparser_parser_t *MParser, bparser_calloc_like_f Calloc) |
| Override the calloc function used internally by the parser. | |
| void * | bparser_set_realloc (bparser_parser_t *MParser, bparser_realloc_like_f Realloc) |
| Override the realloc function used internally by the parser. | |
| void * | bparser_set_free (bparser_parser_t *MParser, bparser_free_like_f Free) |
| Override the free function used internally by the parser. | |
| char | bparser_read_integral (bparser_parser_t *MParser, const char *Name, uint8_t Type, uint8_t Endian) |
| Read an integral from the file. | |
| char | bparser_read_null_str (bparser_parser_t *MParser, const char *Name) |
| Read a null-terminated string from the file. | |
| char | bparser_read_unicode_from_utf8_null_str (bparser_parser_t *MParser, const char *Name) |
| Read unicode codepoints (uint32) from an UTF8 null terminated string from the file. | |
| char | bparser_read_utf8_null_str (bparser_parser_t *MParser, const char *Name) |
| Read an UTF8 null terminated string from the file. | |
| char | bparser_read_fixed_len_str (bparser_parser_t *MParser, const char *Name, size_t Length) |
| Read a string of specified length from the file. | |
| char | bparser_read_unicode_from_utf8_fixed_str (bparser_parser_t *MParser, const char *Name, size_t Length) |
| Read unicode codepoints (uint32) from an UTF8 string of specified length from the file. | |
| char | bparser_read_utf8_fixed_len_str (bparser_parser_t *MParser, const char *Name, size_t Length) |
| Read an UTF8 string of specified length from the file. | |
| char | bparser_read_bytes (bparser_parser_t *MParser, const char *Name, size_t NBytes) |
| Read a specified amount of bytes from the file and store as a simple uint8 array. | |
| char | bparser_read_bytes_and_run (bparser_parser_t *MParser, size_t NBytes, bparser_bytes_f Func) |
| Read a specified amount of bytes from the file and run a function on them. | |
| char | bparser_read_bytes_and_run_sequential (bparser_parser_t *MParser, size_t NBytes, bparser_bytes_seq_f Func) |
| Read a specified amount of bytes and run a function on each one. | |
| char | bparser_read_array (bparser_parser_t *MParser, const char *Name, size_t Items, uint8_t ItemType) |
| Read an array with N items of specified type. | |
| char | bparser_read_2d_array (bparser_parser_t *MParser, const char *Name, size_t Cols, size_t Rows, uint8_t ItemType) |
| Read a 2D array of size NxM items of specified type. | |
| char | bparser_read_float (bparser_parser_t *MParser, const char *Name) |
| Read a float from the file. | |
| char | bparser_read_double (bparser_parser_t *MParser, const char *Name) |
| Read a double from the file. | |
| char | bparser_read_unix_time (bparser_parser_t *MParser, const char *Name) |
| Read a 4 byte unsigned integer number and parse it as an Unix timestamp. | |
| char | bparser_read_8_booleans (bparser_parser_t *MParser, const char *Name) |
| Read 8bits from the file and store each bit as boolean. | |
| char | bparser_read_16_booleans (bparser_parser_t *MParser, const char *Name) |
| Read 16bits from the file and store each bit as boolean. | |
| char | bparser_read_24_booleans (bparser_parser_t *MParser, const char *Name) |
| Read 24bits from the file and store each bit as boolean. | |
| char | bparser_read_32_booleans (bparser_parser_t *MParser, const char *Name) |
| Read 32bits from the file and store each bit as boolean. | |
| char | bparser_read_64_booleans (bparser_parser_t *MParser, const char *Name) |
| Read 64bits from the file and store each bit as boolean. | |
| char | bparser_read_128_booleans (bparser_parser_t *MParser, const char *Name) |
| Read 128bits from the file and store each bit as boolean. | |
| char | bparser_read_bool_and_run (bparser_parser_t *MParser, bparser_bool_handler_f HFunc, bparser_bool_f Func) |
| Read a single byte and run a function on it. | |
| char | bparser_read (bparser_parser_t *MParser, uint8_t *Data, size_t Size) |
| Read data and parse according to saved rules. | |
| char | bparser_fread (bparser_parser_t *MParser, const char *Filename) |
| Read file and parse according to saved rules. | |
| char | bparser_check_magic_num (const uint8_t *Data, const uint8_t *MagicNum, size_t Length) |
| Check magic number. | |
| char | bparser_check_magic_num_char (const uint8_t *Data, const char *MagicNum, size_t Length) |
| Check magic number. | |
| void * | bparser_get (const bparser_parser_t *MParser, const char *Name) |
| Get parsed data. | |
| void | bparser_use_little_endian (bparser_parser_t *MParser) |
| Instruct the parser to use little endian when reading multibyte integral values. | |
| void | bparser_use_big_endian (bparser_parser_t *MParser) |
| Instruct the parser to use big endian when reading multibyte integral values. | |
| char | bparser_seek (bparser_parser_t *MParser, uint64_t Pos, uint8_t Mode) |
| Seek to a position in the file. | |
| char | bparser_rewind (bparser_parser_t *MParser) |
| Seek to beginning of the file. | |
| char | bparser_unwind (bparser_parser_t *MParser) |
| Seek to the end of the file. | |
| const char * | bparser_error_str (char Error) |
| Translate BPARSER_*_ERROR codes into strings. | |
| size_t | bparser_get_data_count (const bparser_parser_t *MParser) |
| Get how many data entries have been stored so far. | |
| size_t | bparser_get_read_order_count (const bparser_parser_t *MParser) |
| Get how many entries have been stored so far in the RO array. | |
| bparser_read_t * | bparser_get_read_order_at (const bparser_parser_t *MParser, size_t Index) |
| Get an entry from RO array. | |
| void * | bparser_read_order_shallow_copy (const bparser_parser_t *MParser, bparser_read_t *Dest) |
| Shallowly copies the RO array. | |
| void * | bparser_read_order_deep_copy (const bparser_parser_t *MParser, bparser_read_t *Dest) |
| Deeply copies the RO array. | |
| char | bparser_parser_set_realloc_method (bparser_parser_t *MParser, double N, uint8_t ReallocMethod) |
| Set the realloc method. | |
| void * | bparser_data_shallow_copy (const bparser_parser_t *MParser, bparser_data_t *Dest) |
| Shallowly copies the data array. | |
| void * | bparser_data_deep_copy (const bparser_parser_t *MParser, bparser_data_t *Dest, char *Failure) |
| Deeply copies the data array. | |
| const bparser_data_t * | bparser_get_data_at (const bparser_parser_t *MParser, size_t Indx) |
| Get the raw bparser_data_t object from the parser. | |
| void | bparser_destroy_read_order (bparser_read_t *Array, size_t Length, bparser_free_like_f FreeCallback) |
| Unallocates a read order (bparser_read_t) array. | |
| void | bparser_destroy_data (bparser_data_t *Array, size_t Length, bparser_free_like_f FreeCallback) |
| Unallocates a data (bparser_data_t) array. | |
| char | bparser_rename (bparser_parser_t *MParser, const char *Src, const char *New) |
| Renames an object in the data array. | |
| void * | bparser_parser_shallow_copy (bparser_parser_t *Src, bparser_parser_t *Dest) |
| Shallowly copies Src parser instance into Dest parser instance. | |
| void * | bparser_parser_deep_copy (bparser_parser_t *Src, bparser_parser_t *Dest, char *Error) |
| Deeply copies Src parser instance into Dest parser instance. | |
| void * | bparser_parser_move (bparser_parser_t *Src, bparser_parser_t *Dest) |
| Using memmove, moves a parser instance. | |
| char | bparser_set_override (bparser_parser_t *MParser, uint8_t Override) |
| Set custom override behaviour. | |
Parser for binary files.
Includes the API for reading and parsing binary files.
| #define BPARSER_BACKWARD_SEEK_ERROR |
Error code for when seeking backwards beyond the beginning of the file.
For example doing bparser_seek(MyParser, 80, BPARSER_SEEK_BACKWARD) on a 20 byte file. However, this is a runtime error, bparser_seek() has no way to return this error itself.
| #define BPARSER_BAD_INTEGRAL_TYPE |
Error code for bparser_read_integral was given a bad integral type.
This happens when you supply the Type argument with an enum other than: BPARSER_UINT8 to BPARSER_INT64, BPARSER_UINT128, BPARSER_INT128, BPARSER_UINT24 or BPARSER_INT24.
| #define BPARSER_BAD_REALLOC_METHOD |
Error code for when bparser_parser_set_realloc_method is fed a bad / unknown realloc method.
This happens when you supply the ReallocMethod arg with anything other than BPARSER_REALLOC_METHOD_PLUS or BPARSER_REALLOC_METHOD_MULT.
| #define BPARSER_BOOL_RUN |
Enum value for reading a boolean and running a function if it's true.
Used internally to specify a boolean and running a function if it's true.
| #define BPARSER_BOOLS |
Enum value for a boolean array.
Used internally to specify a boolean array.
| #define BPARSER_CALLOC_ERROR |
Error code for when calloc fails.
Returned when calloc (or the user-defined function replacing calloc) fails.
| #define BPARSER_DOUBLE |
Enum value for a double datatype.
Used internally to specify a 64bit floating point number.
| #define BPARSER_EOF_ERROR |
Error code for when the parser reaches EOF.
This happens when the parser is told to read more data but it has already reached the end of the file.
| #define BPARSER_FIXED_STR |
Enum value for a string datatype of a set length.
Used internally to specify a string with a fixed size (in characters).
| #define BPARSER_FLOAT |
Enum value for a float datatype.
Used internally to specify a 32bit floating point number.
| #define BPARSER_FSEEK_ERROR |
Error code for when fseek errors out in bparser_fread.
It is important to catch this function erroring out because it is required to get the file size of the specified file.
| #define BPARSER_FTELL_ERROR |
Error code for when ftell errors out in bparser_fread.
It is important to catch this function erroring out because it is required to get the file size of the specified file.
| #define BPARSER_INT128 |
Enum value for an int128 value.
Used to specify an 128bit signed integer number to be read using bparser_read_integral.
| #define BPARSER_INT16 |
Enum value for an int16 value.
Used to specify an 16bit signed integer number to be read using bparser_read_integral.
| #define BPARSER_INT24 |
Enum value for an int24 value.
Used to specify an 24bit signed integer number to be read using bparser_read_integral. Internally the 24bit read value is still stored as 32bit!
| #define BPARSER_INT32 |
Enum value for an int32 value.
Used to specify an 32bit signed integer number to be read using bparser_read_integral.
| #define BPARSER_INT64 |
Enum value for an int64 value.
Used to specify an 64bit signed integer number to be read using bparser_read_integral.
| #define BPARSER_INT8 |
Enum value for an int8 value.
Used to specify an 8bit signed integer number to be read using bparser_read_integral.
| #define BPARSER_N_BYTES |
Enum value for a byte array.
Used internally to specify a byte array.
| #define BPARSER_NAME_IS_NOT_UNIQUE |
Error code for when a name of a read rule that is about to be created is not unique.
| #define BPARSER_RO_ARRAY_ERROR |
Error code for when reallocating the RO array failed.
RO (Read Order) array is what stores what data to read, in what order, what endianess and etc. This is a dynamic array and when it is unable to be expanded (using realloc or the user-defined function replacing realloc) this error code will be returned.
| #define BPARSER_SEEK_BACKWARD |
Enum value used to specify seeking backward.
When used in bparser_seek, it will seek by the given amount backward from the current position.
| #define BPARSER_SEEK_ERROR |
Error code for when an invalid seeking mode is specified to bparser_seek.
This happens when the seeking mode is not BPARSER_SEEK_TO, BPARSER_SEEK_FORWARD, BPARSER_SEEK_BACKWARD or BPARSER_SEEK_FROM_END.
| #define BPARSER_SEEK_FORWARD |
Enum value used to specify seeking forward.
When used in bparser_seek, it will seek by the given amount forward from the current position.
| #define BPARSER_SEEK_FROM_END |
Enum value used to specify seeking from the end.
When used in bparser_seek, it will seek to the specified position from the end.
| #define BPARSER_SEEK_FROM_END_ERROR |
Error code for when seeking from the end goes beyond the beginning of the file.
Same as BPARSER_BACKWARD_SEEK_ERROR.
| #define BPARSER_SEEK_TO |
Enum value used to specify seeking to a certain position.
When used in bparser_seek, it will seek to the specified position.
| #define BPARSER_STR |
Enum value for a string datatype.
Used internally to specify a normal null-terminated string.
| #define BPARSER_UINT128 |
Enum value for an uint128 value.
Used to specify an 128bit unsigned integer number to be read using bparser_read_integral.
| #define BPARSER_UINT16 |
Enum value for an uint16 value.
Used to specify an 16bit unsigned integer number to be read using bparser_read_integral.
| #define BPARSER_UINT24 |
Enum value for an uint24 value.
Used to specify an 24bit unsigned integer number to be read using bparser_read_integral. Internally the 24bit read value is still stored as 32bit!
| #define BPARSER_UINT32 |
Enum value for an uint32 value.
Used to specify an 32bit unsigned integer number to be read using bparser_read_integral.
| #define BPARSER_UINT64 |
Enum value for an uint64 value.
Used to specify an 64bit unsigned integer number to be read using bparser_read_integral.
| #define BPARSER_UINT8 |
Enum value for an uint8 value.
Used to specify an 8bit unsigned integer number to be read using bparser_read_integral.
| #define BPARSER_UNICODE_FROM_UTF8_F_STR |
Enum value for reading unicode codepoints from a fixed length UTF8 string.
Used internally to specify to decode a fixed length UTF8 string and return unicode codepoints (uint32 array).
| #define BPARSER_UNICODE_FROM_UTF8_STR |
Enum value for reading unicode codepoints from a null-terminated UTF8 string.
Used internally to specify to decode an UTF8 string and return unicode codepoints (uint32 array).
| #define BPARSER_UNIX_TIME |
Enum value for the unix timestamp.
Used internally to specify to read a 32bit signed integer as unix timestamp.
| #define BPARSER_UNKNOWN_ENDIAN |
Error code for when the parser encounters an unknown endianess.
This shouldn't happen normally unless you tamper with class variables. This error happens when the parser encounters an endiannes that is not BPARSER_LITTLE_ENDIAN or BPARSER_BIG_ENDIAN.
| #define BPARSER_UNKNOWN_READ_TYPE |
Error code for when the parser encounters an unknown data type.
This shouldn't happen normally unless you tamper with class members. This happens when the parser is told to read a datatype that is not an enum value from BPARSER_UINT8 to BPARSER_BOOL_RUN.
| #define BPARSER_UTF8_F_STR |
Enum value for reading a fixed length UTF8 string.
Used internally to specify to decode a fixed length UTF8 string.
| #define BPARSER_UTF8_STR |
Enum value for reading a null-terminated UTF8 string.
Used internally to specify to decode a null-terminated UTF8 string.
| char bparser_check_magic_num | ( | const uint8_t * | Data, |
| const uint8_t * | MagicNum, | ||
| size_t | Length ) |
Check magic number.
| [in] | Data | Data. |
| [in] | MagicNum | Magic number. |
| [in] | Length | Length of the magic number. |
| char bparser_check_magic_num_char | ( | const uint8_t * | Data, |
| const char * | MagicNum, | ||
| size_t | Length ) |
Check magic number.
| [in] | Data | Data. |
| [in] | MagicNum | Magic number. |
| [in] | Length | Length of the magic number. |
| void * bparser_data_deep_copy | ( | const bparser_parser_t * | MParser, |
| bparser_data_t * | Dest, | ||
| char * | Failure ) |
Deeply copies the data array.
Just like bparser_data_shallow_copy, if Dest is NULL, it is allocated for you, using MParsers' calloc callback function.
| [in] | MParser | Parser instance to copy from. |
| [in] | Dest | Destination bparser_data_t array. |
| [out] | Failure | Error code is written here upon failure. Leave as NULL to ignore. |
| void * bparser_data_shallow_copy | ( | const bparser_parser_t * | MParser, |
| bparser_data_t * | Dest ) |
Shallowly copies the data array.
Despite being similar to memcpy, if Dest is NULL, it allocates it for you. Note however, if you wish for this function to allocate it for you, it will use the MParsers' calloc callback function.
| [in] | MParser | Parser instance to copy from. |
| [in] | Dest | Destination bparser_data_t array. |
| void bparser_destroy | ( | bparser_parser_t * | MParser | ) |
Destroy a parser instance.
| [in] | MParser | The parser to destroy. |
| void bparser_destroy_data | ( | bparser_data_t * | Array, |
| size_t | Length, | ||
| bparser_free_like_f | FreeCallback ) |
Unallocates a data (bparser_data_t) array.
| [in] | Array | The array to destroy. |
| [in] | Length | Length of the array. |
| [in] | FreeCallback | Set to NULL to use default stdc free function, otherwise supply your own callback for freeing memory. |
| void bparser_destroy_read_order | ( | bparser_read_t * | Array, |
| size_t | Length, | ||
| bparser_free_like_f | FreeCallback ) |
Unallocates a read order (bparser_read_t) array.
| [in] | Array | The array to destroy. |
| [in] | Length | Length of the array. |
| [in] | FreeCallback | Set to NULL to use default stdc free function, otherwise supply your own callback for freeing memory. |
| const char * bparser_error_str | ( | char | Error | ) |
Translate BPARSER_*_ERROR codes into strings.
| [in] | Error | Error code. |
| char bparser_fread | ( | bparser_parser_t * | MParser, |
| const char * | Filename ) |
Read file and parse according to saved rules.
| [in] | MParser | Parser instance. |
| [in] | Filename | The file to read. |
| void * bparser_get | ( | const bparser_parser_t * | MParser, |
| const char * | Name ) |
Get parsed data.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable to get. |
| const bparser_data_t * bparser_get_data_at | ( | const bparser_parser_t * | MParser, |
| size_t | Indx ) |
Get the raw bparser_data_t object from the parser.
| [in] | MParser | Parser instance. |
| [in] | Indx | Index. |
| size_t bparser_get_data_count | ( | const bparser_parser_t * | MParser | ) |
Get how many data entries have been stored so far.
| [in] | MParser | Parser instance. |
| bparser_read_t * bparser_get_read_order_at | ( | const bparser_parser_t * | MParser, |
| size_t | Index ) |
Get an entry from RO array.
| [in] | MParser | Parser instance. |
| [in] | Index | Instance. |
| size_t bparser_get_read_order_count | ( | const bparser_parser_t * | MParser | ) |
Get how many entries have been stored so far in the RO array.
| [in] | MParser | Parser instance. |
| bparser_parser_t * bparser_init | ( | bparser_malloc_like_f | MallocLikeFunc, |
| bparser_calloc_like_f | CallocLikeFunc, | ||
| bparser_realloc_like_f | ReallocLikeFunc, | ||
| bparser_free_like_f | FreeLikeFunc ) |
Create a new parser instance.
| [in] | MallocLikeFunc | Use it to override malloc. Leave as NULL to use default functions. |
| [in] | CallocLikeFunc | Use it to override calloc. Leave as NULL to use default functions. |
| [in] | ReallocLikeFunc | Use it to override realloc. Leave as NULL to use default functions. |
| [in] | FreeLikeFunc | Use it to override free. Leave as NULL to use default functions. |
| void * bparser_parser_deep_copy | ( | bparser_parser_t * | Src, |
| bparser_parser_t * | Dest, | ||
| char * | Error ) |
Deeply copies Src parser instance into Dest parser instance.
Under the hood, bparser_read_order_deep_copy and bparser_data_deep_copy are used. Safe to say this is quite a hefty operation. If Dest is NULL, it uses bparser_init to make a new parser instance, to which the Src one is copied into. Note that when bparser_init is called, callbacks for malloc, calloc, realloc and free are copied from Src.
| [in] | Src | Parser instance to copy. |
| [in] | Dest | Destination. |
| [out] | Error | Error code is written here upon failure. |
| void * bparser_parser_move | ( | bparser_parser_t * | Src, |
| bparser_parser_t * | Dest ) |
Using memmove, moves a parser instance.
| [in] | Src | Parser instance to move. |
| [in] | Dest | Where to move it. |
| char bparser_parser_set_realloc_method | ( | bparser_parser_t * | MParser, |
| double | N, | ||
| uint8_t | ReallocMethod ) |
Set the realloc method.
As in, how to resize stuff with realloc. By default, for example with the RO array, the new size is determined by old_size * N. You can use this function to change that * to a + or to change N to however number you like. N here is a double, but obviously it's gonna get floor rounded before fed into realloc.
| [in] | MParser | Parser instance. |
| [in] | N | Factor. |
| [in] | ReallocMethod | Either BPARSER_REALLOC_METHOD_PLUS or BPARSER_REALLOC_METHOD_MULT. |
| void * bparser_parser_shallow_copy | ( | bparser_parser_t * | Src, |
| bparser_parser_t * | Dest ) |
Shallowly copies Src parser instance into Dest parser instance.
Despite being a glorified memcpy, if Dest is null, it uses bparser_init to make a new parser instance, to which the Src one is copied into. Note that when bparser_init is called, callbacks for malloc, calloc, realloc and free are copied from Src.
| [in] | Src | Parser instance to copy. |
| [in] | Dest | Destination. |
| char bparser_read | ( | bparser_parser_t * | MParser, |
| uint8_t * | Data, | ||
| size_t | Size ) |
Read data and parse according to saved rules.
| [in] | MParser | Parser instance. |
| [in] | Data | Array of bytes. |
| [in] | Size | Length of said array of bytes. |
| char bparser_read_128_booleans | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read 128bits from the file and store each bit as boolean.
| [in] | MParser | Parser instance. |
| [in] | Name | Name prefix. Individual boolean values can be accessed as {Name}[{index}]. |
| char bparser_read_16_booleans | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read 16bits from the file and store each bit as boolean.
| [in] | MParser | Parser instance. |
| [in] | Name | Name prefix. Individual boolean values can be accessed as {Name}[{index}]. |
| char bparser_read_24_booleans | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read 24bits from the file and store each bit as boolean.
| [in] | MParser | Parser instance. |
| [in] | Name | Name prefix. Individual boolean values can be accessed as {Name}[{index}]. |
| char bparser_read_2d_array | ( | bparser_parser_t * | MParser, |
| const char * | Name, | ||
| size_t | Cols, | ||
| size_t | Rows, | ||
| uint8_t | ItemType ) |
Read a 2D array of size NxM items of specified type.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this 2D array. |
| [in] | Cols | Number of columns. |
| [in] | Rows | Number of rows. |
| [in] | ItemType | Type of each item. |
| char bparser_read_32_booleans | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read 32bits from the file and store each bit as boolean.
| [in] | MParser | Parser instance. |
| [in] | Name | Name prefix. Individual boolean values can be accessed as {Name}[{index}]. |
| char bparser_read_64_booleans | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read 64bits from the file and store each bit as boolean.
| [in] | MParser | Parser instance. |
| [in] | Name | Name prefix. Individual boolean values can be accessed as {Name}[{index}]. |
| char bparser_read_8_booleans | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read 8bits from the file and store each bit as boolean.
| [in] | MParser | Parser instance. |
| [in] | Name | Name prefix. Individual boolean values can be accessed as {Name}[{index}]. |
| char bparser_read_array | ( | bparser_parser_t * | MParser, |
| const char * | Name, | ||
| size_t | Items, | ||
| uint8_t | ItemType ) |
Read an array with N items of specified type.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this array. |
| [in] | Items | How many items in the array. |
| [in] | ItemType | Type of each item. |
| char bparser_read_bool_and_run | ( | bparser_parser_t * | MParser, |
| bparser_bool_handler_f | HFunc, | ||
| bparser_bool_f | Func ) |
Read a single byte and run a function on it.
HFunc can be left as NULL, in that case, if the boolean is higher than 0, Func will be ran.
| [in] | MParser | Parser instance. |
| [in] | HFunc | Handler function. Decides if Func runs. Leave as NULL for default behaviour. |
| [in] | Func | Function to run when the boolean is true. |
| char bparser_read_bytes | ( | bparser_parser_t * | MParser, |
| const char * | Name, | ||
| size_t | NBytes ) |
Read a specified amount of bytes from the file and store as a simple uint8 array.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this uint8 array. |
| [in] | NBytes | Amount of bytes to read. |
| char bparser_read_bytes_and_run | ( | bparser_parser_t * | MParser, |
| size_t | NBytes, | ||
| bparser_bytes_f | Func ) |
Read a specified amount of bytes from the file and run a function on them.
Does not store the uint8 array afterward.
| [in] | MParser | Parser instance. |
| [in] | NBytes | Amount of bytes to read. |
| [in] | Func | Function to run on the read bytes. |
| char bparser_read_bytes_and_run_sequential | ( | bparser_parser_t * | MParser, |
| size_t | NBytes, | ||
| bparser_bytes_seq_f | Func ) |
Read a specified amount of bytes and run a function on each one.
Does not store the uint8 array afterward.
| [in] | MParser | Parser instance. |
| [in] | NBytes | Amount of bytes to read. |
| [in] | Func | Function to run on the read bytes. |
| char bparser_read_double | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read a double from the file.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this double. |
| char bparser_read_fixed_len_str | ( | bparser_parser_t * | MParser, |
| const char * | Name, | ||
| size_t | Length ) |
Read a string of specified length from the file.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this string. |
| [in] | Length | Length of the string, in bytes. |
| char bparser_read_float | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read a float from the file.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this float. |
| char bparser_read_integral | ( | bparser_parser_t * | MParser, |
| const char * | Name, | ||
| uint8_t | Type, | ||
| uint8_t | Endian ) |
Read an integral from the file.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this integral. |
| [in] | Type | Integral type. |
| [in] | Endian | Endianess to use. |
| char bparser_read_null_str | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read a null-terminated string from the file.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this string. |
| void * bparser_read_order_deep_copy | ( | const bparser_parser_t * | MParser, |
| bparser_read_t * | Dest ) |
Deeply copies the RO array.
Like bparser_read_order_shallow_copy, if Dest is NULL, it is allocated for you. It will use the provided MParsers' calloc callback function for it.
| [in] | MParser | Parser instance to copy from. |
| [in] | Dest | Destination bparser_read_t array. |
| void * bparser_read_order_shallow_copy | ( | const bparser_parser_t * | MParser, |
| bparser_read_t * | Dest ) |
Shallowly copies the RO array.
Despite being similar to memcpy, if Dest is NULL, it allocates it for you. Note however, if you wish for this function to allocate it for you, it will use the MParsers' calloc callback function.
| [in] | MParser | Parser instance to copy from. |
| [in] | Dest | Destination bparser_read_t array. |
| char bparser_read_unicode_from_utf8_fixed_str | ( | bparser_parser_t * | MParser, |
| const char * | Name, | ||
| size_t | Length ) |
Read unicode codepoints (uint32) from an UTF8 string of specified length from the file.
Due to UTF8 encoded codepoints being 1 up to 4 bytes long, Length is given in characters. The library then calculates how many actual bytes will be read and processed.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this uint32 array. |
| [in] | Length | Length of the string, in characters. |
| char bparser_read_unicode_from_utf8_null_str | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read unicode codepoints (uint32) from an UTF8 null terminated string from the file.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this uint32 array. |
| char bparser_read_unix_time | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read a 4 byte unsigned integer number and parse it as an Unix timestamp.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this timestamp. |
| char bparser_read_utf8_fixed_len_str | ( | bparser_parser_t * | MParser, |
| const char * | Name, | ||
| size_t | Length ) |
Read an UTF8 string of specified length from the file.
Due to UTF8 encoded codepoints being 1 up to 4 bytes long, Length is given in characters. The library then calculates how many actual bytes will be read and processed.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this UTF8 string. |
| [in] | Length | Length of the string, in characters. |
| char bparser_read_utf8_null_str | ( | bparser_parser_t * | MParser, |
| const char * | Name ) |
Read an UTF8 null terminated string from the file.
| [in] | MParser | Parser instance. |
| [in] | Name | Name of the variable later used to get this UTF8 string. |
| char bparser_rename | ( | bparser_parser_t * | MParser, |
| const char * | Src, | ||
| const char * | New ) |
Renames an object in the data array.
| [in] | MParser | Parser instance. |
| [in] | Src | Source name to rename. |
| [in] | New | New name. |
| char bparser_rewind | ( | bparser_parser_t * | MParser | ) |
Seek to beginning of the file.
| [in] | MParser | Parser instance. |
| char bparser_seek | ( | bparser_parser_t * | MParser, |
| uint64_t | Pos, | ||
| uint8_t | Mode ) |
Seek to a position in the file.
| [in] | MParser | Parser instance. |
| [in] | Pos | Position. |
| [in] | Mode | Seeking mode. |
| void * bparser_set_calloc | ( | bparser_parser_t * | MParser, |
| bparser_calloc_like_f | Calloc ) |
Override the calloc function used internally by the parser.
| [in] | MParser | Parser instance. |
| [in] | Calloc | Your function of type bparser_calloc_like_f, or NULL to use the standard library calloc. |
| void * bparser_set_free | ( | bparser_parser_t * | MParser, |
| bparser_free_like_f | Free ) |
Override the free function used internally by the parser.
| [in] | MParser | Parser instance. |
| [in] | Free | Your function of type bparser_free_like_f, or NULL to use the standard library free. |
| void * bparser_set_malloc | ( | bparser_parser_t * | MParser, |
| bparser_malloc_like_f | Malloc ) |
Override the malloc function used internally by the parser.
| [in] | MParser | Parser instance. |
| [in] | Malloc | Your function of type bparser_malloc_like_f, or NULL to use the standard library malloc. |
| char bparser_set_override | ( | bparser_parser_t * | MParser, |
| uint8_t | Override ) |
Set custom override behaviour.
This is used to tell the parser what to do to fix an issue with two read rules having the same name.
| [in] | MParser | Parser instance. |
| [in] | Override | Enum value either BPARSER_OVERRIDE_ERROR, BPARSER_OVERRIDE_TRUE, BPARSER_OVERRIDE_SKIP or BPARSER_OVERRIDE_DO_NOTHING. |
| void * bparser_set_realloc | ( | bparser_parser_t * | MParser, |
| bparser_realloc_like_f | Realloc ) |
Override the realloc function used internally by the parser.
| [in] | MParser | Parser instance. |
| [in] | Realloc | Your function of type bparser_realloc_like_f, or NULL to use the standard library realloc. |
| void bparser_shallow_destroy | ( | bparser_parser_t * | MParser | ) |
Destroys a shallow copy of a parser instance.
ONLY use this on shallow copies. This effectively destroys the copy without freeing the RO and Data pointers. If you have parser B that is a deep copy of parser A, use bparser_destroy on parser A, and bparser_shallow_destroy on parser B, to avoid both memory leaks and double free-ing!
| [in] | MParser | Parser instance. |
| char bparser_unwind | ( | bparser_parser_t * | MParser | ) |
Seek to the end of the file.
| [in] | MParser | Parser instance. |
| void bparser_use_big_endian | ( | bparser_parser_t * | MParser | ) |
Instruct the parser to use big endian when reading multibyte integral values.
| [in] | MParser | Parser instance. |
| void bparser_use_little_endian | ( | bparser_parser_t * | MParser | ) |
Instruct the parser to use little endian when reading multibyte integral values.
| [in] | MParser | Parser instance. |