C++ implementation for a binary data storage format.

bsmlib- A C++ library for loading and writing binary data to and from files.

bsmlib provides functions for loading, modifying, and saving BSM (Binary Small Data) formatted data. To include this library, add files from the include directory to your include path or linker, and files from the src path to your source path. To compile as a static library, check the documentation for your compiler (such as here for GCC).

File specifications

Supported types:

  • Integers (32-bit)
  • Floats
  • Strings
  • Raw data
Max size/length
Keys 255
Keyname 16
Data region 131072 (128kb)

Using with C++

After including the library with #include <bsmlib.hpp>, access all the bsmlib functions in the bsmlib namespace through the bsmlib::Data class.

Setting and getting keys

#include <bsmlib.hpp>

int main() {
	std::vector<uint8_t> data_bytes = {0x02, 0x03, 0x05, 0x08, 0x0D, 0x15, 0x22, 0x37};
	
	bsmlib::Data my_data;

	my_data.SetInt("my_int", 2022);
	my_data.SetFloat("my_float", 3.14159f);
	my_data.SetString("my_string", "Hello, world!");
	my_data.SetRaw("my_raw", data_bytes);

	std::cout << "Int:        " << my_data.GetInt("my_int") 	<< std::endl;
	std::cout << "Float:      " << my_data.GetFloat("my_float") 	<< std::endl;
	std::cout << "String:     " << my_data.GetString("my_string") 	<< std::endl;
	std::cout << "Raw (size): " << my_data.GetRaw("my_raw").size()	<< std::endl;
	
	return 0;
}

Saving and loading files

Use bsmlib::Data::Save(std::string filename) to save to a file.

bsmlib::Data my_data;
// ...
my_data.Save("data.bsm");

Use bsmlib::Data::Load(std::string filename) to load from a file.

bsmlib::Data my_data;
my_data.Load("data.bsm");

OR, pass a filename as an std::string to the constructor to automatically load data from a file.

bsmlib::Data my_data("data.bsm");

Deleting a key

Deleting a key is as simple as calling bsmlib::Data::DeleteKey(std::string filename)

Testing if key exists

If you want to know if a key exists, call bsmlib::Data::KeyExists(std::string filename). It will return true if a key exists by the given name, and false if it does not.

BSM file structure

The bsmlib.hpp file contains a simple text markup of the layout of the file.

[1] - Key table size (# of keys)

[*] Key table { (21 bytes each)
    [16] - Name
    [1]  - Type (0 = Int, 1 = Float, 2 = String, 3 = Raw)
    [2]  - Data offset  /  Value low word
    [2]  - Data size    /  Value high hide
}

[*] - Data region

The first byte of the file signifies the number of keys stored. For the given table size, each entry is 21 bytes long. The first 16 bytes stores the name of the key, the 17th byte stores the type, and the 18th to 21st bytes store either the data region info or value depending on the keys type. Integers and floats get their data stored in the last 4 bytes of every table entry. Strings and raws use the 18th and 19th bytes to store their data's offset from the beginning of the data region, and the 20th and 21st bytes to store the length of their data. Note: All values are stored in little-endian format.

Owner
Colleen
Hobbyist Programmer, 17 yr old; She/Her
Colleen
Similar Resources

A simple console client for pCloud cloud storage.

pCloud Console Client A simple console client for pCloud cloud storage. Project Information pCloud Console Client was forked from the project initiall

Mar 14, 2022

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.

中文版本请参看这里 MMKV is an efficient, small, easy-to-use mobile key-value storage framework used in the WeChat application. It's currently available on Andr

May 15, 2022

Modern transactional key-value/row storage library.

Modern transactional key-value/row storage library.

Sophia is advanced transactional MVCC key-value/row storage library. How does it differ from other storages? Sophia is RAM-Disk hybrid storage. It is

May 7, 2022

A demonstration PoC for CVE-2022-21877 (storage spaces controller memory leak)

A demonstration PoC for CVE-2022-21877 (storage spaces controller memory leak)

POC CVE-2022-21877 This repository contains a POC for the CVE-2022-21877, found by Quang Linh, working at STAR Labs. This is an information leak found

Mar 8, 2022

PlotFS is a fuse filesystem for efficient storage of Chia plot files.

PlotFS PlotFS is a fuse filesystem for efficient storage of Chia plot files. PlotFS is not a traditional filesystem. It is mounted read only for farmi

Apr 24, 2022

This is a tool for software engineers to view,record and analyse data(sensor data and module data) In the process of software development.

This is a tool for software engineers to view,record and analyse data(sensor data and module data) In the process of software development.

![Contributors][Huang Jianyu] Statement 由于工具源码在网上公开,除使用部分开源项目代码外,其余代码均来自我个人,工具本身不包含公司的知识产权,所有与公司有关的内容均从软件包中移除,软件发布遵循Apache协议,任何人均可下载进行修改使用,如使用过程中出现任何问

May 5, 2022

A simple processor emulator written in c++ that can parse and execute x32 code. x32 is binary code made by me for this processor.

A SIMPLE PROCESSOR EMULATOR AND CODE EXECUTOR The Repository This is a fairly new project and is still heavy in development. If you find and bugs feel

Jan 20, 2022

A HEIF/HEIC addon for Pillow using libheif library through CFFI, with binary wheels.

pillow_heif A HEIF/HEIC addon for Pillow using libheif library through CFFI, with binary wheels(Python 3.6-3.9, linux/macos - x64,aarch64). Based most

May 20, 2022
Related tags
Spacex Storage is an offchain storage work inspector of Mannheim Network running inside TEE enclave.

Spacex Storage Spacex Storage is an offchain storage work inspector of Mannheim Network running inside TEE enclave. Contribution Thank you for conside

Mar 22, 2022
IconVG is a compact, binary format for simple vector graphics: icons, logos, glyphs and emoji.
IconVG is a compact, binary format for simple vector graphics: icons, logos, glyphs and emoji.

IconVG IconVG is a compact, binary format for simple vector graphics: icons, logos, glyphs and emoji. WARNING: THIS FORMAT IS EXPERIMENTAL AND SUBJECT

May 12, 2022
A library to handle Apple Property List format in binary or XML

libplist A small portable C library to handle Apple Property List files in binary or XML format. Features The project provides an interface to read an

Apr 26, 2022
(Simple String Format) is an syntax of format and a library for parse this.

SSFMT (Simple String Format) is an syntax of format and a library for parse this. SSFMT != {fmt} SSFMT is NOT an API/library for parse {fmt} syntax !

Jan 30, 2022
Using D2XX driver to capture UART data to a binary file

What is it This is the sample code to read UART data using any baud rate that FTDI supports and save them to a binary file. How to use Usage: ./larger

Nov 24, 2021
Binary data analysis and visualization tool
Binary data analysis and visualization tool

Veles - A new age tool for binary analysis It is a very difficult task for a human to notice subtle patterns in large amounts of binary data, however,

May 14, 2022
May 14, 2022
Poseidon OS (POS) is a light-weight storage OS

Poseidon OS Poseidon OS (POS) is a light-weight storage OS that offers the best performance and valuable features over storage network. POS exploits t

May 17, 2022
MinIO C++ Client SDK for Amazon S3 Compatible Cloud Storage

The MinIO C++ Client SDK provides simple APIs to access any Amazon S3 compatible object storage.

May 10, 2022
XTAO Unified Distributed Storage

Anna - A branch project from CEPH Anna is a XTAO project branched from CEPH distributed storage. CEPH is a nice opensource project for unified distrib

Nov 12, 2021