Skip to content

ZBinaryIO is a modern, header-only, cross-platform C++17 binary reader/writer library.

License

Notifications You must be signed in to change notification settings

pawREP/ZBinaryIO

Repository files navigation

ZBinaryIO

Build Status codecov Codacy Badge

ZBinaryIO is a modern, header-only, cross-platform C++17 binary reader/writer library.

The library provides binary read and write interfaces for files and buffers. Additional data sources and sinks can be supported via implementations of the ISource and ISink interfaces. Sources and sinks can also easily extended using the mixin pattern. See CoverageTrackingSource for an example of such an extension.

Basic Usage

using namespace ZBio;

// Reader
ZBinaryReader br("example.bin");

// Read fundamental types
int intLe = br.read<int>();
int intBe = br.read<int, Endianness::BE>();

//Align read head
br.align<0x10>();

// Read strings
std::string str0 = br.readCString(); //Read null-terminated string
std::string str1 = br.readString<4>(); //Read fixed size strings

//Read arrays
std::vector<int> ints(10);
br.read(ints.data(). ints.size())

//Read trivially copyable types
struct TrivialStruct{int a; float b; double c}
auto s = br.read<TrivialStruct>();

br.release(); // Release reader resources.

// Writer 
ZBinaryWriter bw("example.bin");

bw.write(3); // Write fundamental types
bw.write<long long, Endianness::BE>(5); // Write fundamental types, explicit type and endianness

bw.writeString("Test"); // Write string
bw.writeCString("Test"); // Write null-terminated string

// Write trivially copyable type
TrivialStruct ts{1, 2, 3.25};
bw.write(ts); 

// Write arrays
std::vector<int> wints(10);
br.write(wints.data(). wints.size())

// Release writer resources
bw.release();

CI

ZBinaryIO is continuously compiled and tested on:

  • gcc 9.3.0
  • clang 9.0.0
  • MSVC 2019 ver. 16.5 (1925)

About

ZBinaryIO is a modern, header-only, cross-platform C++17 binary reader/writer library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published