This repository contains the reusabe functions, macros and constantes being used across all my projects.
PLATFORM_WINDOWS
is defined when compiling in Windows Environment (OS)PLATFORM_LINUX
is defined when compiling in Linux Environment (OS)PLATFORM_APPLE
is defined when compiling in MacOS Environment (OS)
BIT64(index)
macro returns a 64-bit unsigned integer with only single bit set at the index passed asindex
BIT32(index)
macro returns a 32-bit unsigned integer with only single bit set at the index passed asindex
BIT16(index)
macro returns a 16-bit unsigned integer with only single bit set at the index passed asindex
BIT8(index)
macro returns a 8-bit unsigned integer with only single bit set at the index passed asindex
BIT_MASK32(count)
macro returns a 32-bit unsigned integer with its right mostcount
bits setBIT16_PACK8(v1, v2)
macro returns a 16-bit unsigned integer with its left most 8 bits encodev1
and the right most 8 bits encodev2
BIT16_UNPACK8(bits, index)
macro returns a 8-bit unsigned integer corresponding to the 8 bits starting atindex x 8
bit index from the leftBIT32_PACK16(v1, v2)
macro returns a 32-bit unsigned integer with its left most 16 bits encodev1
and the right most 16 bits encodev2
BIT32_UNPACK16(bits, index)
macro returns a 16-bit unsigned integer corresponding to the 16 bits starting atindex x 16
bit index from the leftBIT32_PACK8(v1, v2, v3, v4)
macro returns 32-bit unsigned integer having packed 8-bit valuesv1
,v2
,v3
, andv4
sequentially from left to rightBIT32_UNPACK8(bits, index)
macro returns 8-bit unsigned integer corresponding to the 8 bits starting atindex x 8
from the leftBIT64_PACK32(v1, v2)
macro returns 64-bit unsigned integer having packed 32-bit valuesv1
, andv2
from left to rightBIT64_UNPACK32(bits, index)
macro returns 32-bit unsigned integer corresponding to the 32-bits starting atindex x 32
from the left
com_assert(condition, description)
prints description and breaks the execution whencondition
is false, and it only works inGLOBAL_DEBUG
modecom_assert_wrn(condition, description)
issues only a warning whencondition
is false, and it only works inGLOBAL_DEBUG
modecom_assert_called_once()
when called inside any function, it make sures the function is called only once in the lifetime of a program otherwise it prints an error and breaks the execution, and it only works inGLOBAL_DEBUG
modecom_assert_not_implemented()
when called inside any function, it issues an error when the function is called indicating the function is not implemented yet and not suitable for any use, and it only works inGLOBAL_DEBUG
mode_com_assert(condition)
works same ascom_assert
function, however it doesn't require a description, it prints the condition expression as it is, and it only works inGLOBAL_DEBUG
mode_com_assert_wrn(condition)
works same ascom_assert_wrn
function, however it doesn't require a description as second argument, it prints the condition expression as it is, and it only works inGLOBAL_DEBUG
mode
Given a string of bytes, either loaded from file residing in disk or already existing in the memory as BUFFER
(a.k.a buffer_t
) object, the set of functions in common/binary_reader.h
header can be used to read formatted data out of those bytes.
Example:
// include <disk_manager/file_reader.h> to use load_binary_from_file() function
BUFFER* data = load_binary_from_file("myFile.bin");
// create binary_reader_t object from the base pointer and the number of bytes it points to
binary_reader_t* reader = binary_reader_create(buf_get_ptr(data), buf_get_element_count(data))
// destroy the binary_reader_t object
binary_reader_destroy(reader)
// destroy the BUFFER object
buf_free(data)