|
From: stephan b. <st...@s1...> - 2004-12-18 23:30:52
|
This certainly isn't a world-first, but it is a first for s11n:
i've just serialized a list<> over http, using a PHP proxy script to
store it in a mysql db as raw text, and then deserialized it back over
http. The implementation probably only works for small data sets,
because i'm using http GET and a hell of a lot of space-to-%20
encoding, but the work was fairly trivial - even the encoding part fit
right in to the existing Serializer model.
The client-side code is trivial:
Create and save an object:
typedef std::list<lext::lex_t> ListT;
ListT li;
li.push_back( 42 );
li.push_back( -42.42 );
li.push_back( "fourty two" );
li.push_back( 'x' );
bool workie;
if( ! P::s11n::save( li, "http://s11n/ps11n.php?node_name=name" ) )
{
... failed :( ...
}
Load a node:
P::s11n::node_type * node =
P::s11n::load_node( "http://s11n/ps11n.php?node_name=name" );
"Completely" deserialize it with:
ListT li;
bool worked = P::s11n::deserialize( *node, li );
delete node;
Note that http://s11n/ is my local machine, not s11n.net.
Test output:
Write an object:
stephan@owl: > m && ./test
<snip>
test.cpp:36 : test_writeurl()
// the object we're writing to the URL:
test.cpp:47 : list<lex_t>:
(s11n::parens)
data_node=(list
data_node=(lex_t (v 42))
data_node=(lex_t (v -42.420000))
data_node=(lex_t (v fourty two))
data_node=(lex_t (v x))
)
ps11n.hpp:220 : serialize(node,
[http://s11n/ps11n.php?node_name=egal])...
<snip>
stephan@owl:~/cvs/s11n.net/ps11n/src> echo $?
0
Load it back:
stephan@owl: > m && ./test 'http://s11n/ps11n.php?node_name=egal'
test.cpp:15 : test_readurl()
test.cpp:25 : node ? = 0x80b9c58
// the data we got from the web server:
(s11n::parens)
data_node=(list
data_node=(lex_t (v 42))
data_node=(lex_t (v -42.420000))
data_node=(lex_t (v fourty two))
data_node=(lex_t (v x))
)
The PHP quick-hack http/mysql proxy is attached, and the db code is
simply:
CREATE TABLE ps11n (
id int(11) NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
data longtext,
PRIMARY KEY (name,id),
UNIQUE KEY id (id),
KEY name (name)
) TYPE=MyISAM;
The ID field isn't strictly neccessary, though.
--
----- st...@s1... http://s11n.net
"...pleasure is a grace and is not obedient to the commands
of the will." -- Alan W. Watts
|