forked from lordoffox/adata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiongxiaolei
committed
Feb 2, 2015
1 parent
772f09a
commit a79ec61
Showing
26 changed files
with
5,499 additions
and
5,541 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
ADATA v1.0 | ||
======= | ||
|
||
ADATA is an C++ serialization library. | ||
|
||
Features Overview | ||
--------------- | ||
|
||
* Lightweight, fast and efficient serialization implementations | ||
* Only one macro to register C++ struct, one line code that's all | ||
* Header only, no need to build library, just three hpp files | ||
* Support C++03 and C++11 (Need AMSG_STD_CXX11 macro) | ||
* Default support C++ built-in types and all std containters (include C++11's) | ||
|
||
What is AMSG? | ||
--------------- | ||
|
||
```cpp | ||
struct person | ||
{ | ||
std::string name; | ||
int age; | ||
|
||
bool operator==(person const& rhs) const | ||
{ | ||
return name == rhs.name && age == rhs.age; | ||
} | ||
}; | ||
|
||
AMSG(person, (name)(age)); | ||
|
||
#define ENOUGH_SIZE 4096 | ||
unsigned char buf[ENOUGH_SIZE]; | ||
|
||
// serialize | ||
person src; | ||
src.name = "lordoffox" | ||
src.age = 33 | ||
|
||
amsg::zero_copy_buffer writer(buf, ENOUGH_SIZE); | ||
amsg::write(writer, src); | ||
assert(!writer.bad()); | ||
|
||
// deserialize | ||
person des; | ||
|
||
amsg::zero_copy_buffer reader(buf, ENOUGH_SIZE); | ||
amsg::read(reader, des); | ||
assert(!reader.bad()); | ||
|
||
assert(src == des); | ||
``` | ||
Dependencies | ||
------------ | ||
* CMake 2.8 and newer | ||
* Boost 1.55.0 and newer (Header only) | ||
Supported Compilers | ||
------------------- | ||
* GCC >= 4.6 | ||
* VC >= 9.0 (sp1) | ||
Support C++11 | ||
------------------- | ||
Define AMSG_STD_CXX11 in your project or just before include amsg hpps | ||
```cpp | ||
#define AMSG_STD_CXX11 | ||
#include <amsg/all.hpp> | ||
// C++11's forward_list | ||
#include <forward_list> | ||
std::forward_list<int> fwd_list = {1,2,3,4,5}; | ||
unsigned char buf[4096]; | ||
amsg::zero_copy_buffer writer(buf, 4096); | ||
amsg::write(writer, fwd_list); | ||
assert(!writer.bad()); | ||
``` | ||
|
||
amsg::size_of | ||
------------------- | ||
|
||
Using amsg::size_of to get object's serialize size | ||
|
||
```cpp | ||
struct person | ||
{ | ||
std::string name; | ||
int age; | ||
|
||
bool operator==(person const& rhs) const | ||
{ | ||
return name == rhs.name && age == rhs.age; | ||
} | ||
}; | ||
|
||
AMSG(person, (name)(age)); | ||
|
||
person obj; | ||
amsg::error_code_t ec = amsg::success; | ||
std::size_t size = amsg::size_of(obj, ec); | ||
assert(ec == amsg::success); | ||
std::cout << "person's serialize size: " << size << std::endl; | ||
``` | ||
smax | ||
------------------- | ||
Sometimes you want limit max size of an array of string: | ||
```cpp | ||
struct person | ||
{ | ||
std::string name; | ||
int age; | ||
bool operator==(person const& rhs) const | ||
{ | ||
return name == rhs.name && age == rhs.age; | ||
} | ||
}; | ||
AMSG(person, (name&smax(30))(age)); // smax(30) limit name string max size is 30 bytes | ||
``` | ||
|
||
sfix | ||
------------------- | ||
|
||
Sometimes you want serialization size to be fixed: | ||
|
||
```cpp | ||
struct person | ||
{ | ||
std::string name; | ||
boost::int32_t age; | ||
|
||
bool operator==(person const& rhs) const | ||
{ | ||
return name == rhs.name && age == rhs.age; | ||
} | ||
}; | ||
|
||
AMSG(person, (name)(age&sfix)); // sfix enforce age (int32_t) to be 4bytes after serialization | ||
``` | ||
If no sfix, age will dependence its value: | ||
-128 to 127 --> 1byte | ||
-32,768 to 32,767 --> 2byte | ||
-2,147,483,648 to 2,147,483,647 --> 4byte | ||
note: sfix only effect built-in types(int, short, long, char, float, double and so on). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
# | ||
# This file is part of the CMake build system for adata gen | ||
# This file is part of the CMake build system for adl | ||
# | ||
# CMake auto-generated configuration options. | ||
# Do not check in modified versions of this file. | ||
# | ||
# Copyright (c) 2014-2014 lordoffox (QQ:99643412 [email protected]) | ||
# Copyright (c) 2014-2015 lordoffox (QQ:99643412 [email protected]) | ||
# Copyright (c) 2015 Nous Xiong (QQ:348944179 [email protected]) | ||
# | ||
# Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
# | ||
|
||
cmake_minimum_required (VERSION 2.8.6 FATAL_ERROR) | ||
project (adata_gen) | ||
project (adl) | ||
|
||
# The version number. | ||
set (ADATA_VERSION_MAJOR 0) | ||
set (ADATA_VERSION_MINOR 1) | ||
|
||
option (STL_USE_STATIC_LIBS "Build stl runtime static" OFF) | ||
option (ADATA_STATIC "Build adata_gen runtime static" OFF) | ||
|
||
if (UNIX) | ||
set (STL_USE_STATIC_LIBS,OFF) | ||
set (ADATA_STATIC,OFF) | ||
endif () | ||
set (ADL_VERSION_MAJOR 1) | ||
set (ADL_VERSION_MINOR 0) | ||
|
||
if (WIN32) | ||
set (WINVER "0x0501" CACHE STRING "Windows version maro. Default is 0x0501 - winxp, user can reset") | ||
|
@@ -34,50 +27,15 @@ if (MSVC) | |
add_definitions (-D__CRT_SECURE_NO_WARNINGS) | ||
endif() | ||
|
||
# Set glibc. | ||
if (ADATA_STATIC) | ||
set (GLIBC_INCLUDEDIR "" CACHE PATH "Path to glibc include directory") | ||
set (GLIBC_LIBRARYDIR "" CACHE PATH "Path to glibc libraries directory") | ||
if (GLIBC_INCLUDEDIR) | ||
include_directories (${GLIBC_INCLUDEDIR}) | ||
endif () | ||
if (GLIBC_LIBRARYDIR) | ||
link_directories (${GLIBC_LIBRARYDIR}) | ||
endif () | ||
endif () | ||
|
||
# Add the source and build tree to the search path for include gce header files. | ||
include_directories (${PROJECT_SOURCE_DIR}) | ||
include_directories (${PROJECT_BINARY_DIR}) | ||
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../include/) | ||
#stl libraries option | ||
if(STL_USE_STATIC_LIBS) | ||
if(MSVC) | ||
add_definitions (-D_STATIC_CPPLIB) | ||
set(CompilerFlags | ||
CMAKE_CXX_FLAGS | ||
CMAKE_CXX_FLAGS_DEBUG | ||
CMAKE_CXX_FLAGS_RELEASE | ||
CMAKE_CXX_FLAGS_MINSIZEREL | ||
CMAKE_CXX_FLAGS_RELWITHDEBINFO | ||
CMAKE_C_FLAGS | ||
CMAKE_C_FLAGS_DEBUG | ||
CMAKE_C_FLAGS_RELEASE | ||
CMAKE_C_FLAGS_MINSIZEREL | ||
CMAKE_C_FLAGS_RELWITHDEBINFO | ||
) | ||
foreach(CompilerFlag ${CompilerFlags}) | ||
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") | ||
endforeach() | ||
endif () | ||
if(CMAKE_COMPILER_IS_GNUCXXX) | ||
endif () | ||
endif () | ||
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../cpp/) | ||
|
||
# Boost libraries search. | ||
set (Boost_USE_STATIC_LIBS ON) | ||
set (Boost_USE_MULTITHREADED ON) | ||
if (ADATA_STATIC) | ||
if (ADL_STATIC) | ||
set (Boost_USE_STATIC_RUNTIME ON) | ||
else () | ||
set (Boost_USE_STATIC_RUNTIME OFF) | ||
|
@@ -98,13 +56,33 @@ link_directories (${Boost_LIBRARY_DIRS}) | |
|
||
set (CMAKE_VERBOSE_MAKEFILE true) | ||
|
||
if (NOT WIN32) | ||
set (ADL_COMPILE_PROP "-std=c++11") | ||
if (APPLE) | ||
set (ADL_COMPILE_PROP "${ADL_COMPILE_PROP} -stdlib=libc++") | ||
endif () | ||
endif () | ||
|
||
if (WIN32) | ||
if (${CMAKE_GENERATOR} MATCHES "Visual Studio 11 *" OR ${CMAKE_GENERATOR} MATCHES "Visual Studio 12 *") | ||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") | ||
endif () | ||
endif () | ||
|
||
file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") | ||
add_executable(adata_gen ${SOURCE_FILES}) | ||
add_executable(adl ${SOURCE_FILES}) | ||
|
||
if (ADL_COMPILE_PROP) | ||
set_target_properties (adl PROPERTIES COMPILE_FLAGS "${ADL_COMPILE_PROP}") | ||
endif () | ||
target_link_libraries (adl ${Boost_LIBRARIES}) | ||
|
||
install (TARGETS adl RUNTIME DESTINATION bin) | ||
|
||
# Build a CPack driven installer package. | ||
include (InstallRequiredSystemLibraries) | ||
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt") | ||
set (CPACK_PACKAGE_VERSION_MAJOR "${ADATA_VERSION_MAJOR}") | ||
set (CPACK_PACKAGE_VERSION_MINOR "${ADATA_VERSION_MINOR}") | ||
set (CPACK_PACKAGE_VERSION_MAJOR "${ADL_VERSION_MAJOR}") | ||
set (CPACK_PACKAGE_VERSION_MINOR "${ADL_VERSION_MINOR}") | ||
set (CPACK_PACKAGE_CONTACT "QQ:99643412 lordoffox: [email protected]") | ||
include (CPack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Boost Software License - Version 1.0 - August 17th, 2003 | ||
|
||
Permission is hereby granted, free of charge, to any person or organization | ||
obtaining a copy of the software and accompanying documentation covered by | ||
this license (the "Software") to use, reproduce, display, distribute, | ||
execute, and transmit the Software, and to prepare derivative works of the | ||
Software, and to permit third-parties to whom the Software is furnished to | ||
do so, all subject to the following: | ||
|
||
The copyright notices in the Software and this entire statement, including | ||
the above license grant, this restriction and the following disclaimer, | ||
must be included in all copies of the Software, in whole or in part, and | ||
all derivative works of the Software, unless such copies or derivative | ||
works are solely in the form of machine-executable object code generated by | ||
a source language processor. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT | ||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE | ||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
/// | ||
/// Copyright (c) 2014-2015 Ning Ding ([email protected]) | ||
/// Copyright (c) 2015 Nous Xiong ([email protected]) | ||
/// | ||
/// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
/// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
/// | ||
/// See https://github.com/lordoffox/adata for latest version. | ||
/// | ||
|
||
#include "descrip.h" | ||
#include "util.h" | ||
|
Oops, something went wrong.