Skip to content

Latest commit

 

History

History
85 lines (62 loc) · 2.51 KB

README.md

File metadata and controls

85 lines (62 loc) · 2.51 KB

Seriously C++ serialization library

Seriously is an header-only C++ serialization library, without external dependencies (besides the standard library) and with minimal overhead.

Serialized data is encoded in a portable fashion (i.e. words are encoded in network byte order, ...).

Example Code

The higher-level API:

#include <iostream>
#include <string>
#include <vector>
#include <stdint.h>

#include "Seriously.h"

void myfunc()
{
	seriously::Packer<1024> packer;		// a 1024 byte serialization buffer

	int32_t value1 = 83656;
	bool value2 = true;
	int16_t value3 = -2345;
	std::string value4("only an example");
	double value5 = -6.736;
	std::vector<int64_t> value6 = { 42, 11, 93 };

	packer << value1 << value2 << value3 << value4 << value5 << value6;

	std::cout << "packed size: " << packer.size() << std::endl;
	// packer.data() contains the serialized data

	int32_t restored1;
	bool restored2;
	int16_t restored3;
	std::string restored4;
	double restored5 = -6.736;
	std::vector<int64_t> restored6;

	packer >> restored1 >> restored2 >> restored3 >> restored4 >> restored5 >> restored6;

	std::cout << "unpacked: " << restored1 << " " << (restored2 ? "t" : "f") << " " << restored3 << " " << restored4 << " " << restored5 << std::endl;

	std::vector<int64_t>::const_iterator it;
	for (it = restored6.begin(); it != restored6.end(); it++) {
		std::cout << *it << std::endl;
	}
}

It's possible to extend support to more esotic types by implementing a Traits struct for each additonal type.

See the test_seriously.cpp unit test file for a more complete API coverage.

Usage

Just copy the Seriously.h and Seriously.impl.hpp files into your source code and include only the former.

License

Seriously is distributed under the Apache License, Version 2.0 See the NOTICE file distributed with this work for additional information regarding copyright ownership. The author licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.