https://github.com/koute/cdata
https://github.com/koute/cdata
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/koute/cdata
- Owner: koute
- License: gpl-3.0
- Created: 2012-07-11T10:48:44.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2013-04-26T18:01:47.000Z (about 13 years ago)
- Last Synced: 2025-03-18T07:17:08.827Z (about 1 year ago)
- Language: Ruby
- Size: 148 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
What is cdata?
--------------
CData lets you serialize arbitrary Ruby structures into static C++ data.
Try running this:
require 'cdata'
s = CData::Serializer.new
s.serialize [ 1, 2, 3 ], 'g_array'
s.source_prologue << '#include "data.h"'
s.generate
File.open( "data.h", "wb" ) { |fp| fp.puts s.header }
File.open( "data.cpp", "wb" ) { |fp| fp.puts s.source }
Then compile this:
#include
#include "data.h"
int main()
{
for( auto value: g_array )
printf( "%i\n", value );
return 0;
}
Output:
$ g++ data.cpp main.cpp -std=c++0x
$ ./a.out
1
2
3
Supported features
-----------------
* All basic Ruby types (Integers, Arrays, Hashes, Strings, etc.)
* Custom user defined types. (Just define self.cdata_methods() that returns
a list of symbols you want serialized.)
* Space efficient - variable types are picked according to the content.
For example - if you only have integers less than 256 in an array then
they will be serialized as unsigned chars.)
* Cyclic dependencies between objects.