Skip to content
Snippets Groups Projects
Commit 5e9cab83 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

added encode/decode for storing SGML in caches

Rev: tutorial/Sgml.pmod:1.15
parent 18d57cef
Branches
Tags
No related merge requests found
...@@ -273,6 +273,52 @@ string get_text(SGML data) ...@@ -273,6 +273,52 @@ string get_text(SGML data)
} }
class Codec
{
string nameof(mixed o)
{
if(objectp(o)) return ([])[0];
if(o==Tag) return "TAG";
error("Cannot encode that!\n");
}
program functionof(string p)
{
if(p=="TAG") return Tag;
}
mixed encode_object(object o)
{
return ({
o->tag,
o->pos,
o->params,
o->data,
o->file
});
}
void decode_object(object o, mixed data)
{
[ o->tag,
o->pos,
o->params,
o->data,
o->file ] = data;
}
}
string encode(SGML data)
{
return encode_value(data,Codec());
}
SGML decode(string data)
{
return decode_value(data,Codec());
}
#ifdef TEST #ifdef TEST
int main() int main()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment