Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

362 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

BCSV - Binary CSV for Time-Series Data

Fast, compact, and easy-to-use binary format for time-series data
Combines CSV simplicity with binary performance and compression

License: MIT C++20 Version

Versioning: Since v1.5.0, library version and file format version are unified. A single version (from git tags) is stamped into every .bcsv file header. Package versions (PyPI, NuGet) track the same version. See VERSIONING.md for details.


What is BCSV?

BCSV combines the ease of use of CSV files with the performance and storage efficiency of binary formats. It's specifically designed for time-series data on both high-performance and embedded platforms.

Key Features

  • ๐Ÿ“ฆ 15-25% of CSV size with LZ4 compression (3-4% with Zero-Order Hold)
  • ๐Ÿš€ 3.6M-7.5M rows/second processing speed (8-33 columns, Zen3 CPU)
  • ๐ŸŽฏ Self-documenting format - no separate schema files needed
  • ๐ŸŒŠ Streaming I/O - process datasets larger than available RAM
  • ๐Ÿ›ก๏ธ Crash-resilient - recover data from incomplete writes
  • ๐ŸŒ Multi-language - C++, Python, C#/Unity support
  • โšก Real-time capable - constant-time operations for embedded systems

Target Users

Anyone running metrology, data acquisition, or telemetry tasks - from embedded systems to HPC clusters.


Quick Start

Installation

Header-only library - just include the directory:

#include <bcsv/bcsv.h>  // C++ API

Or build with CMake:

cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
./build/bin/bcsv_gtest  # Run tests

5-Minute Example

#include <bcsv/bcsv.h>
#include <iostream>

int main() {
    // Define schema
    bcsv::Layout layout;
    layout.addColumn({"timestamp", bcsv::ColumnType::DOUBLE});
    layout.addColumn({"temperature", bcsv::ColumnType::FLOAT});
    layout.addColumn({"sensor_id", bcsv::ColumnType::UINT16});

    // Write data
    bcsv::Writer<bcsv::Layout> writer(layout);
    if (!writer.open("measurements.bcsv", true)) {
        std::cerr << writer.getErrorMsg() << "\n";
        return 1;
    }

    writer.row().set(0, 1234567890.0);
    writer.row().set(1, 23.5f);
    writer.row().set(2, uint16_t{42});
    writer.writeRow();
    writer.close();

    // Read data
    bcsv::Reader<bcsv::Layout> reader;
    if (!reader.open("measurements.bcsv")) {
        std::cerr << reader.getErrorMsg() << "\n";
        return 1;
    }

    while (reader.readNext()) {
        auto timestamp = reader.row().get<double>(0);
        auto temp = reader.row().get<float>(1);
        auto id = reader.row().get<uint16_t>(2);
        std::cout << "Sensor " << id << ": " << temp << "ยฐC @ " << timestamp << "\n";
    }
}

See examples/quickstart.cpp for a self-contained runnable version. For delta encoding, direct access, and error handling examples, see examples/.

Result: 84% size reduction (105MB CSV โ†’ 16.3MB BCSV) with full type safety.


Documentation

๐Ÿ“š Core Documentation

๐ŸŽฏ Getting Started

๐Ÿ“Š Performance & Benchmarks

  • benchmark/README.md - Benchmark quick-start and script-friendly run options
  • tests/PERFORMANCE_COMPARISON.md - Detailed benchmarks and comparisons
  • Typical speeds: 3.6M rows/sec (flexible), 7.5M rows/sec (static), 127K rows/sec (1000 columns)
  • Compression: 15-25% of CSV size (LZ4), 3-4% with Zero-Order Hold

Run benchmarks locally:

# Quick macro smoke run (default)
python3 benchmark/run.py wip

# Direct macro CLI overview (profiles/scenarios/examples)
build/ninja-release/bin/bench_macro_datasets --help

# Direct macro run with compact summary (narrow terminal friendly)
build/ninja-release/bin/bench_macro_datasets --size=S --summary=compact

# Micro benchmark pinned to CPU2
python3 benchmark/run.py wip --type=MICRO --pin=CPU2

# Combined campaign
python3 benchmark/run.py wip --type=MICRO,MACRO-SMALL,MACRO-LARGE

# Manual compare report (candidate vs baseline)
python3 benchmark/report.py <candidate_run_dir> --baseline <baseline_run_dir>

14 dataset profiles ร— multiple mode combinations (storage ร— codec), with optional external CSV library comparison. See benchmark/README.md for details.


Supported Platforms & Languages

Language Integration Best For Guide
C++ Header-only, C++20 Maximum performance (static API) examples/
Python pip install pybcsv Pandas workflows, prototyping python/README.md
C# dotnet add package Bcsv .NET services, Sampler, columnar I/O csharp/README.md
Unity UPM Git URL or tarball Game development, recording unity/README.md
C Shared library (libbcsv) FFI bindings, embedded systems docs/API_OVERVIEW.md

All APIs produce identical binary format โ€” files are 100% cross-compatible. See docs/INTEROPERABILITY.md and docs/API_OVERVIEW.md for code examples and comparison matrix.

Minimum Toolchain Requirements

BCSV requires C++20 with full library support for <span>, <bit>, <concepts>, and <stop_token>.

Platform Compiler / Toolchain Minimum Version Notes
Linux x86/x64 GCC 13.1+ -std=c++20 -pthread
Linux x86/x64 Clang + libstdc++ 16+ with libstdc++ 13+ -std=c++20 -fbracket-depth=512
Windows x64 MSVC (Visual Studio) VS 2022 17.4+ (MSVC 19.34+) /std:c++20 /W4
macOS x64/ARM Apple Clang (Xcode) Xcode 15.4+ -std=c++20; Xcode 15.0โ€“15.3 lacks <stop_token>
macOS Homebrew Clang/GCC GCC 13+ or LLVM 17+ Alternative to Apple Clang
STM32 (Linux) Arm GNU Toolchain GCC 13.2+ (CubeIDE 1.14+) Embedded Linux on STM32MP1/MP2
AMD/Xilinx (Linux) Vitis / PetaLinux 2024.1+ (GCC 13+) Zynq, ZynqMP, Kria, Versal with Linux

Build system: CMake โ‰ฅ 3.28, Ninja (recommended) or Make.

Embedded baremetal note: BCSV currently requires std::fstream for I/O and uses C++ exceptions for logic errors. Baremetal/RTOS targets (STM32 F4/F7/H7, Zynq without Linux) lack filesystem and POSIX threading support, so BCSV does not build on baremetal without an I/O abstraction layer. See ARCHITECTURE.md for details.


Project Status

Current Version: v1.5.8

Delivered

  • โœ… Streaming LZ4 compression with constant write latency
  • โœ… File indexing (FileFooter) for O(log N) random access (ReaderDirectAccess)
  • โœ… Delta + VLE row codec (RowCodecDelta002) โ€” 2.3% of CSV size
  • โœ… Five file codec strategies (stream, stream-LZ4, packet, packet-LZ4, packet-LZ4-batch)
  • โœ… Sampler API โ€” bytecode VM for row filtering and column projection
  • โœ… 11 CLI tools including bcsvSampler, bcsvGenerator, bcsvValidate, bcsvRepair, bcsvCast, bcsvCompare
  • โœ… Python (pybcsv) with pandas/Polars integration
  • โœ… C# NuGet package with Sampler, CSV interop, columnar I/O
  • โœ… Unity UPM package with native binaries
  • โœ… Unified versioning (library = file format = packages)

Roadmap

  • v2.0.0 (Q2 2026): Stable release with compatibility guarantees

โš ๏ธ Development Notice: Until v2.0.0, file formats may change between minor versions. Use for experimentation and non-critical storage.


Project Structure

bcsv/
โ”œโ”€โ”€ include/bcsv/          # ๐Ÿ“ฆ Header-only library (copy this to integrate)
โ”‚   โ”œโ”€โ”€ bcsv.h             #    Main include file
โ”‚   โ”œโ”€โ”€ reader.hpp         #    Reader implementation
โ”‚   โ”œโ”€โ”€ writer.hpp         #    Writer implementation
โ”‚   โ””โ”€โ”€ ...                #    Supporting headers
โ”‚
โ”œโ”€โ”€ docs/                  # ๐Ÿ“š User-facing documentation
โ”‚   โ”œโ”€โ”€ API_OVERVIEW.md    #    Multi-language API comparison
โ”‚   โ”œโ”€โ”€ ERROR_HANDLING.md  #    Error handling guide
โ”‚   โ””โ”€โ”€ INTEROPERABILITY.md#    Cross-language compatibility
โ”‚
โ”œโ”€โ”€ examples/              # ๐ŸŽฏ Usage examples (11 programs)
โ”‚   โ”œโ”€โ”€ quickstart.cpp     #    Minimal 5-minute example
โ”‚   โ”œโ”€โ”€ example.cpp        #    Basic flexible-layout usage
โ”‚   โ”œโ”€โ”€ example_static.cpp #    Static-layout usage
โ”‚   โ””โ”€โ”€ ...                #    delta, ZoH, direct access, error handling, sampler, visitor
โ”‚
โ”œโ”€โ”€ src/tools/             # ๐Ÿ”ง CLI tools (11 utilities)
โ”‚   โ”œโ”€โ”€ csv2bcsv.cpp       #    CSV โ†’ BCSV converter
โ”‚   โ”œโ”€โ”€ bcsv2csv.cpp       #    BCSV โ†’ CSV converter
โ”‚   โ”œโ”€โ”€ bcsvSampler.cpp    #    Filter & project rows
โ”‚   โ””โ”€โ”€ ...                #    bcsvHead, bcsvTail, bcsvHeader, bcsvGenerator, bcsvValidate, bcsvRepair
โ”‚
โ”œโ”€โ”€ tests/                 # โœ… Comprehensive test suite (784 tests)
โ”œโ”€โ”€ python/                # ๐Ÿ Python package (pip install pybcsv)
โ”œโ”€โ”€ csharp/                # ๐Ÿ’ผ C# NuGet package (dotnet add package Bcsv)
โ”œโ”€โ”€ unity/                 # ๐ŸŽฎ Unity UPM integration
โ”œโ”€โ”€ docs/                  # ๐Ÿ“– Thread safety, error handling, interop, lean checklist
โ”œโ”€โ”€ cmake/                 # ๐Ÿ”ง Build system utilities
โ”‚
โ”œโ”€โ”€ ARCHITECTURE.md        # ๐Ÿ—๏ธ  Design and technical specification
โ”œโ”€โ”€ VERSIONING.md          # ๐Ÿ“‹ Version management
โ””โ”€โ”€ README.md              # ๐Ÿ‘‹ This file

Key Concepts

Data Types

Supports 12 types: BOOL, UINT8/16/32/64, INT8/16/32/64, FLOAT, DOUBLE, STRING

All types are stored in little-endian format with IEEE 754 for floating point. See docs/INTEROPERABILITY.md.

Bit-exactness guarantee: the binary format round-trips every IEEE-754 bit pattern โ€” NaN (including payload bits), ยฑInf, signed zero (-0.0), and subnormals โ€” through all row codecs (flat, ZoH, delta) on both the flexible and static APIs. The CSV bridge (csv2bcsv/bcsv2csv, CsvWriter/CsvReader) preserves special values (nan, inf, -inf, -0) but not NaN payload bits.

Flexible vs Static API

  • Flexible (Runtime): Dynamic schemas, runtime validation, 3.6M rows/sec
  • Static (Compile-Time): Type-safe templates, compile-time validation, 7.5M rows/sec

See docs/API_OVERVIEW.md for detailed comparison.

Error Handling

  • I/O operations return bool - check return value and use getErrorMsg()
  • Row access throws exceptions - catch std::out_of_range and std::runtime_error

See docs/ERROR_HANDLING.md for complete guide.


Building & Testing

Build Commands

Build and test:

# Configure and build
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

# Run tests
ctest --test-dir build --output-on-failure

# Try examples
./build/bin/example
./build/bin/csv2bcsv data.csv

Python package:

cd python/
pip install -e .  # Development mode

CMake integration:

add_subdirectory(external/bcsv)
target_link_libraries(your_target PRIVATE bcsv)

Dependencies

  • LZ4 (v1.10.0) โ€” bundled in include/lz4-1.10.0/
  • xxHash (v0.8.3) โ€” bundled in include/xxHash-0.8.3/
  • C++20 Standard Library โ€” <span>, <bit>, <concepts>, <stop_token>, <thread>, <fstream>
  • No external runtime dependencies โ€” header-only, copy include/ and compile

Build/test only:

  • Google Test (auto-fetched via CMake FetchContent)
  • nanobind (auto-fetched for Python bindings)

License & Contributing

MIT License - Copyright (c) 2025 Tobias Weber. See LICENSE.

BCSV bundles third-party components under permissive BSD licenses โ€” LZ4 and xxHash (BSD-2-Clause) in the library, and CLI11 (BSD-3-Clause) in the CLI tools. Their copyright notices are reproduced in the LICENSE file.

Contributions welcome! Please open issues for bugs/features and include tests with PRs.


Ready to start? Check out examples/ or docs/API_OVERVIEW.md for detailed API documentation.

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages