From: stephan b. <st...@s1...> - 2004-12-19 11:36:40
|
s11n now supports 9 (count 'em: 9) data transport layers, including http. This new format is a bit unusual in that it proxies arbitrary formats, and doesn't really provide a data format itself. For writing it defaults to using 'funtxt', but for loading it supports any format supported by s11nlite. Plugging in P's http-based serializer required no s11n-level changes, as we can dynamically load the serializer via the name 'phttp' and treat it like any other Serializer: Witness: A s11n data file: ~> cat in.s11n (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)) ) Import it from the file and re-save it over the web: ~> s11nconvert -f in.s11n -s phttp -o 'http://s11n/ps11n.php?node_name=sumdumlist' // -f == input file // -s == output serializer // -o == output file Now it's in the db: ~> mysql -e 'select id,name from ps11n' ps11n +----+------------+ | id | name | +----+------------+ | 15 | bar | | 28 | bob | | 29 | boo | | 19 | egal | | 1 | foo | | 26 | fred | | 33 | mylist | HERE ----> | 34 | sumdumlist | | 24 | thelist | | 32 | wow | | 23 | yourlist | +----+------------+ Now load it, saving it to stdout in another format: ~> s11nconvert -f 'http://s11n/ps11n.php?node_name=sumdumlist' -S phttp -s funxml // -f == input file // -S == *force* input serializer phttp // (it cannot yet be dynamically dispatched this way) // -s == output serializer The output: <!DOCTYPE SerialTree> <data_node class="list"> <data_node class="lex_t"> <v>42</v> </data_node> <data_node class="lex_t"> <v>-42.420000</v> </data_node> <data_node class="lex_t"> <v>fourty two</v> </data_node> <data_node class="lex_t"> <v>x</v> </data_node> </data_node> Cool, eh? It also plugs in to the s11nbrowser interface: http://s11n.net/s11nbrowser/ see the last 2 screenshots. Caveats: a) because i'm using http GET, saving is probably limited to relatively small, not-extremely-complex objects. i'll figure out how to resolve this later on. Loading should work for arbitrarily large data, as long as it can all fit in a std::string buffer. b) if you pass a non-well-formed URL it may cause a segfault in P::URL, catch() notwithstanding: s11nconvert -f in.s11n -s phttp -o not_a_http_url Aborted c) Never call s11nlite::serializer_class("phttp"). That will set s11nlite's default output format to phttp, and will hose things. s11nlite tries to save it's config post-main() and probably can't if phttp is it's default output format. d) If using s11nbrowser, make sure to accidentally do (c) by accident (it's easy to do). e) When saving/loading to/from a stream, e.g., save(obj,cout) it writes using its proxy format, and does no http operations. -- ----- st...@s1... http://s11n.net "...pleasure is a grace and is not obedient to the commands of the will." -- Alan W. Watts |