All Projects → RedSkittleFox → BinaryLove3

RedSkittleFox / BinaryLove3

Licence: MIT license
Simple C++ 20 Serialization Library that works out of the box with aggregate types!

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to BinaryLove3

Yaxlib
Yet Another XML Serialization Library for the .NET Framework and .NET Core
Stars: ✭ 124 (+853.85%)
Mutual labels:  serialization, serialization-library
Hprose Php
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP
Stars: ✭ 1,952 (+14915.38%)
Mutual labels:  serialization, serialization-library
Json
Lighter and Faster Json Serialization tool.
Stars: ✭ 128 (+884.62%)
Mutual labels:  serialization, serialization-library
Succ
Sexy and Utilitarian Code Configuration
Stars: ✭ 100 (+669.23%)
Mutual labels:  serialization, serialization-library
json5
Header only JSON/JSON5 parser and serializer for C++
Stars: ✭ 22 (+69.23%)
Mutual labels:  serialization, cpp20
Hprose Delphi
Hprose is a cross-language RPC. This project is Hprose 2.0 for Delphi and FreePascal
Stars: ✭ 100 (+669.23%)
Mutual labels:  serialization, serialization-library
ikeapack
Compact data serializer/packer written in Go, intended to produce a cross-language usable format.
Stars: ✭ 18 (+38.46%)
Mutual labels:  serialization, serialization-library
Hprose Java
Hprose is a cross-language RPC. This project is Hprose 2.0 for Java
Stars: ✭ 542 (+4069.23%)
Mutual labels:  serialization, serialization-library
Thorsserializer
C++ Serialization library for JSON
Stars: ✭ 241 (+1753.85%)
Mutual labels:  serialization, serialization-library
Hprose Html5
Hprose is a cross-language RPC. This project is Hprose 2.0 Client for HTML5
Stars: ✭ 237 (+1723.08%)
Mutual labels:  serialization, serialization-library
JsonFormatter
Easy, Fast and Lightweight Json Formatter. (Serializer and Deserializer)
Stars: ✭ 26 (+100%)
Mutual labels:  serialization, serialization-library
EndianBinaryIO
A C# library that can read and write primitives, enums, arrays, and strings to streams and byte arrays with specified endianness, string encoding, and boolean sizes.
Stars: ✭ 20 (+53.85%)
Mutual labels:  serialization, serialization-library
Hprose Golang
Hprose is a cross-language RPC. This project is Hprose for Golang.
Stars: ✭ 1,143 (+8692.31%)
Mutual labels:  serialization, serialization-library
Lora Serialization
LoraWAN serialization/deserialization library for The Things Network
Stars: ✭ 120 (+823.08%)
Mutual labels:  serialization, serialization-library
Eminim
JSON serialization framework for Nim, works from a Stream directly to any type and back. Depends only on stdlib.
Stars: ✭ 32 (+146.15%)
Mutual labels:  serialization, serialization-library
Hprose Js
Hprose is a cross-language RPC. This project is Hprose 2.0 RPC for JavaScript
Stars: ✭ 133 (+923.08%)
Mutual labels:  serialization, serialization-library
Hprose Nodejs
Hprose is a cross-language RPC. This project is Hprose 2.0 for Node.js
Stars: ✭ 297 (+2184.62%)
Mutual labels:  serialization, serialization-library
Typedefs
Programming language agnostic type construction language based on polynomials.
Stars: ✭ 337 (+2492.31%)
Mutual labels:  serialization, serialization-library
Persistentstorageserializable
Swift library that makes easier to serialize the user's preferences (app's settings) with system User Defaults or Property List file on disk.
Stars: ✭ 162 (+1146.15%)
Mutual labels:  serialization, serialization-library
Simple-Log
dnkpp.github.io/Simple-Log/
Stars: ✭ 13 (+0%)
Mutual labels:  cpp20, cpp20-library

MSVC Unit Tests

BinaryLove3

Simple C++ 20 Serialization Library that works out of the box with aggregate types!

Requirements

BinaryLove3 is a c++20 only library. Library can serialize only types matching these requirements:

  • trivial types (e.g. uint32_t, struct { uint32_t a; float_t b; }):

    Types matching requirements for std::is_trivial.

  • agregate types (e.g. std::pair, struct { uint32_t a; std::vector<uint32_t> b; }):

    Types matching requirements for std::is_aggregate.

  • iterable types (e.g. std::vector):

    Type is required to be compatible with std::begin, std::end and std::inserter. Additionally member type value_type is also required.

    If type's iterator fulfils std::random_access_iterator requirement and value_type matches requirement is_trivial then optimisations will be made.

  • types providing specializations for BinaryLove3::serialize and BinaryLove3::deserialize. Refer to Providing custom serialization methods

Usage

// demo.cpp

#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <string>
#include <list>

#include "BinaryLove3.hpp"

struct foo
{
	uint32_t v0 = 3;
	uint32_t v1 = 2;
	float_t v2 = 2.5f;
	char v3 = 'c';
	struct
	{
		std::vector<int> vec_of_trivial = { 1, 2, 3 };
		std::vector<std::string> vec_of_nontrivial = { "I am a Fox!", "In a big Box!" };
		std::string str = "Foxes can fly!";
		std::list<int> non_random_access_container = { 3, 4, 5 };
	} non_trivial;
	struct
	{
		uint32_t v0 = 1;
		uint32_t v1 = 2;
	} trivial;
};

auto main() -> int32_t
{
	foo out = { 4, 5, 6.7f, 'd', {{5, 4, 3, 2}, {"cc", "dd"}, "Fly me to the moon..." , {7, 8, 9}}, {3, 4} };
	auto data = BinaryLove3::serialize(bobux);
	
	foo in;
	BinaryLove3::deserialize(data, in);
	return int32_t(0);
}

Providing custom serialization methods.

One can provide custom serialization methods by creating specializations for the following functions:

  • std::vector<std::byte> serialize(const T& var_)
  • bool deserialize(const std::byte*& cur_, const std::byte* end_, T& obj_)
#include <BinaryLove3>

class foo
{
  friend std::vector<std::byte> serialize(const foo& var_);
  friend bool deserialize(const std::byte*& cur_, const std::byte* end_, foo& obj_);
private:
  uint32_t m_a;
  std::vector<uint32_t> m_b;
public:
  void foo_method();
}

std::vector<std::byte> serialize(const foo& var_)
{
  auto ret = BinaryLove3::serialize(var_.m_a);
  auto data = BinaryLove3::serialize(var_.m_b);
  ret.insert(std::end(insert), std::begin(data), std::end(data));
  return ret;
}

bool deserialize(const std::byte*& cur_, const std::byte* end_, foo& obj_)
{
  uint32_t a;
  std::vector<uint32_t> b;
  if(!BinaryLove3::deserialize(cur_, end_, a))
    return false;
  
  if(!BinaryLove3::deserialize(cur_, end_, b))
    return false;
    
  obj_.m_a = std::move(a);
  obj_.m_b = std::move(b);
  
  return true;
}

Notes

This library works only with up to 10 member variables of an aggregate type right now. This will be expanded in the near future. Cheers!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].