Logo de Aster Système

SCLS Foundation - Binary

The precise code to use each binaries tools ("Bytes_Set" and all) are documentated below.
Contenu

Handle binary

Handle bits and bytes

As the C++ is a very low level language, you may need to use binary directly in it. To handle it correctly, SCLS Foundation offers a set of tools, allowing to safely and fastly handle binary. SCLS provides a special class which contains every needed objects : the "Bytes_Set" class. However, some others functions are usable outside of the class.

contenu

Documentation

The "Bytes_Set" class

Bytes_Set()

Most simple "Bytes_Set" constructor. Construct an empty "Bytes_Set" object.

Bytes_Set(unsigned int new_datas_size)

Create a Bytes_Set object with a predefined size of "new_datas_size" bytes.

Bytes_Set(char* new_datas, unsigned int new_datas_size)

Create a new Bytes_Set object with the datas pointed in "new_datas", with a "new_datas_size" bytes size. Be careful, the datas in "new_datas" are not copied, but used directly in the Bytes_Set.

Bytes_Set(const Bytes_Set

Copy constructor of Bytes_Set.

~Bytes_Set()

Destructor of Bytes_Set.

inline void add_datas(char* datas_to_add, unsigned int datas_to_add_size)
inline void add_datas(const char* datas_to_add, unsigned int datas_to_add_size)

Add the datas "datas_to_add" (of size "datas_to_add_size" in bytes) in the Bytes_Set.

inline void add_datas(const Bytes_Set

Add the datas in the Bytes_Set "datas_to_add" in this Bytes_Set.

inline void add_data(char data)

Add a single byte "data" of datas in the Bytes_Set.

inline void add_double(double data, bool big_endian = false)
inline void add_float(float data, bool big_endian = false)
inline void add_short(short data, bool big_endian = false)
inline void add_ushort(unsigned short data, bool big_endian = false)
inline void add_int(int data, bool big_endian = false)
inline void add_int64(int64_t data, bool big_endian = false)
inline void add_uint(unsigned int data, bool big_endian = false)

Add the "data" in the Bytes_Set, with the needed encoding type (specified by the type). You can also specify if a big-endian modification must be applied or not.

inline void add_string(std::string text)

Add the string "text" to the Bytes_Set.

inline char data_at(unsigned int position) const

Returns the value of the bytes at the "position" index. If the position is incorrect, an error is printed and 0 is returned.

inline char data_at_directly(unsigned int position) const

This method is faster than data_at(), because it does not apply the security check for the binary handling. However, DON'T USE IT if you are not sure that binaries error can't occurs.

inline char* datas() const

Returns a pointer to the datas stored in the Bytes_Set.

inline unsigned int datas_size() const

Returns the size of the datas in the Bytes_Set in bytes.

inline char* extract_datas(unsigned int extract_size, unsigned int offset = 0, bool inverse = false) const

Returns a char array of extracted datas from the Bytes_Set, with a size of "extract_size" and starting at the position "offset" (included). An inverse modification can be added too, with "inverse".

inline double extract_double(unsigned int offset = 0, bool big_endian = false) const
inline float extract_float(unsigned int offset = 0, bool big_endian = false) const
inline int extract_int(unsigned int offset = 0, bool big_endian = false) const
inline int64_t extract_int64(unsigned int offset = 0, bool big_endian = false) const
inline short extract_short(unsigned int offset = 0, bool big_endian = false) const
inline unsigned int extract_uint(unsigned int offset = 0, bool big_endian = false) const
inline unsigned short extract_ushort(unsigned int offset = 0, bool big_endian = false) const

Extract a numerical value at the "offset" position, with the encoding value asked by the used type. You can also specify if a big-endian modification must be applied or not.

inline std::string extract_string(unsigned int extract_size, unsigned int offset = 0)

Extract a piece of text of a size "extract_size" at the position "offset".

inline void free_memory()

Free the memory by deleting all the datas in the Bytes_Set.

inline bool load_from_file(std::string path)

Set the datas in the Bytes_Set at the datas at a file "path", and returns if the operation went good or not.

inline void save(std::string path) const

Save the datas in the Bytes_Set in a file "path".

inline void set_data_at(unsigned int position, char new_data)

Set the byte at the "position" index to "new_data".

inline void set_data_at_directly(unsigned int position, char new_data)

Sets the data at the given "position" the given value "new data". This method is faster than set_data_at(), because the securities checks are not happening. However, DON'T USE IT if you are not sure that binaries error can't occurs.

char operator[] (unsigned int position)

Returns the byte at the "position" index in the Bytes_Set.