I'm looking for code to translate objects to XML and back with absolutely NO pike specific encoding of any kind. Is this already available or do I have to make this myself?
What do you mean by that? You want to encode arbitrary pike objects in XML?
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
I'm looking for code to translate objects to XML and back with absolutely NO pike specific encoding of any kind. Is this already available or do I have to make this myself?
-- Met vriendelijke groet / With kind regards / mit besten Gr��en,
Coen Schalkwijk
Software Engineer
coen.schalkwijk@rtl.nl mailto:coen.schalkwijk@rtl.nl
coen@rtlinteractief.nl mailto:coen@rtlinteractief.nl
+31 (0)35 671 8915
Yes, for example (a very naive one); from a pike string "hello world" to <string>hello world</string>
Greetings Coen
On 12-1-2011 14:03, Arne Goedeke wrote:
What do you mean by that? You want to encode arbitrary pike objects in XML?
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
I'm looking for code to translate objects to XML and back with absolutely NO pike specific encoding of any kind. Is this already available or do I have to make this myself?
-- Met vriendelijke groet / With kind regards / mit besten Gr??en,
Coen Schalkwijk
Software Engineer
coen.schalkwijk@rtl.nl <mailto:coen.schalkwijk@rtl.nl> coen@rtlinteractief.nl <mailto:coen@rtlinteractief.nl> +31 (0)35 671 8915
I dont know if something like this exists. But have you considered using JSON? It works quite well for all standard types, has far less overhead than xml and is easier to parse.
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
Yes, for example (a very naive one); from a pike string "hello world" to <string>hello world</string>
Greetings Coen
On 12-1-2011 14:03, Arne Goedeke wrote:
What do you mean by that? You want to encode arbitrary pike objects in XML?
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
I'm looking for code to translate objects to XML and back with absolutely NO pike specific encoding of any kind. Is this already available or do I have to make this myself?
-- Met vriendelijke groet / With kind regards / mit besten Gr??en,
Coen Schalkwijk
Software Engineer
coen.schalkwijk@rtl.nl <mailto:coen.schalkwijk@rtl.nl> coen@rtlinteractief.nl <mailto:coen@rtlinteractief.nl> +31 (0)35 671 8915
Its for storing objects in a database and usage from within multiple different environments. I'll look into JSON. Does pike offer Object-JSON-Object support? If so, could you help me out with a quick example?
On 12-1-2011 15:12, Arne Goedeke wrote:
I dont know if something like this exists. But have you considered using JSON? It works quite well for all standard types, has far less overhead than xml and is easier to parse.
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
Yes, for example (a very naive one); from a pike string "hello world" to <string>hello world</string>
Greetings Coen
On 12-1-2011 14:03, Arne Goedeke wrote:
What do you mean by that? You want to encode arbitrary pike objects in XML?
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
I'm looking for code to translate objects to XML and back with
absolutely NO pike specific encoding of any kind. Is this already available or do I have to make this myself?
-- > Met vriendelijke groet / With kind regards / mit besten
Gr??en,
> > Coen Schalkwijk
Software Engineer
coen.schalkwijk@rtl.nl <mailto:coen.schalkwijk@rtl.nl> coen@rtlinteractief.nl <mailto:coen@rtlinteractief.nl> +31 (0)35 671 8915
>
In any case you will need to know which kinds of objects you want to serialize and come up with some kind of serialization. The Pike JSON module supports encoding arbitrary objects using a callback. But you still need to specify by hand which object variables you want to serialize, etc. Also, when you need to decode the objects again from their json representation you will need to build some code that does this. there is no reasonable way to do this automatically.
You could for instance do something like this
class A { string a, b, c; mapping d, e;
string encode_json() { return JSON.encode(([ "class" : "A", "a" : a, "b" : b, .... ])); } }
This would then be encoded as a mapping, which you would need to transform back into the object depending on the "class".
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
Its for storing objects in a database and usage from within multiple different environments. I'll look into JSON. Does pike offer Object-JSON-Object support? If so, could you help me out with a quick example?
On 12-1-2011 15:12, Arne Goedeke wrote:
I dont know if something like this exists. But have you considered using JSON? It works quite well for all standard types, has far less overhead than xml and is easier to parse.
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
Yes, for example (a very naive one); from a pike string "hello world" to <string>hello world</string>
Greetings Coen
On 12-1-2011 14:03, Arne Goedeke wrote:
What do you mean by that? You want to encode arbitrary pike objects in XML?
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
I'm looking for code to translate objects to XML and back with
absolutely NO pike specific encoding of any kind. Is this already available or do I have to make this myself?
> -- > Met vriendelijke groet / With kind regards / mit besten
Gr??en,
> > > Coen Schalkwijk
Software Engineer
coen.schalkwijk@rtl.nl <mailto:coen.schalkwijk@rtl.nl> coen@rtlinteractief.nl <mailto:coen@rtlinteractief.nl> +31 (0)35 671 8915
> >
Thanks for your suggestion. Is it possible in pike to do/use/consume something like 'they' do in dotNET:
[XMLNode name="A"] classA{ [XMLNode name="aVar"] string a; [XMLNode name="cookieCount"] int b; }
On 12-1-2011 16:53, Arne Goedeke wrote:
In any case you will need to know which kinds of objects you want to serialize and come up with some kind of serialization. The Pike JSON module supports encoding arbitrary objects using a callback. But you still need to specify by hand which object variables you want to serialize, etc. Also, when you need to decode the objects again from their json representation you will need to build some code that does this. there is no reasonable way to do this automatically.
You could for instance do something like this
class A { string a, b, c; mapping d, e;
string encode_json() { return JSON.encode(([ "class" : "A", "a" : a, "b" : b, .... ])); }
}
This would then be encoded as a mapping, which you would need to transform back into the object depending on the "class".
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
Its for storing objects in a database and usage from within multiple different environments. I'll look into JSON. Does pike offer Object-JSON-Object support? If so, could you help me out with a quick example?
On 12-1-2011 15:12, Arne Goedeke wrote:
I dont know if something like this exists. But have you considered using JSON? It works quite well for all standard types, has far less overhead than xml and is easier to parse.
arne
On Wed, 12 Jan 2011, Coen Schalkwijk wrote:
Yes, for example (a very naive one); from a pike string "hello
world" to > <string>hello world</string>
Greetings Coen On 12-1-2011 14:03, Arne Goedeke wrote: What do you mean by that? You want to encode arbitrary pike
objects > > in
XML?
> arne > On Wed, 12 Jan 2011, Coen Schalkwijk wrote: > > > I'm looking for code to translate objects to XML and
back with > > > absolutely NO pike specific encoding of any kind. Is this already > > > available or do I have to make this myself?
> > -- > Met vriendelijke groet / With kind regards / mit
besten > > Gr??en,
> > > > Coen Schalkwijk Software Engineer > coen.schalkwijk@rtl.nl mailto:coen.schalkwijk@rtl.nl > coen@rtlinteractief.nl mailto:coen@rtlinteractief.nl > +31 (0)35 671 8915 > > > >
On Wed, Jan 12, 2011 at 5:01 PM, Coen Schalkwijk coen.schalkwijk@rtl.nl wrote:
Thanks for your suggestion. Is it possible in pike to do/use/consume something like 'they' do in dotNET:
Simple answer: no, this is not possible in Pike. More exact answer: you could implement this with a preprocessor (using Parser.Pike to tokenize the Pike source code) extracting the formatting meta information from your classes etc., and then run that either one time in the process (every time you change the code) or even include it in the Pike compilation process (i. e. when pike loads foo.pike and compiles it) - both possible, and both probably way easier in Pike than in any other language.
Tobi
On 12/01/11 17:01, Coen Schalkwijk wrote:
Thanks for your suggestion. Is it possible in pike to do/use/consume something like 'they' do in dotNET:
[XMLNode name="A"] classA{ [XMLNode name="aVar"] string a; [XMLNode name="cookieCount"] int b; }
There is no real need for this when it is so easy to look into objects, iterate, etc.
To map special names to variables, just use a mapping:
mapping XMLNames = ([ classA : ([ "a" : "aVar", "b" : "cookieCount" ]), classB : ([ "a" : "aVar", "b" : "somethingElse" ]) ]);
mapping default_XMLNames = ([ "a" : "aVar" ]);
object o = get_object(); mapping o_xml_names = XMLNames[object_program(o)] || default_XMLNames;
foreach (o; string var_name; mixed val) { string name = o_xml_names[var_name]; if (!name) continue; /* add to xml */ }
This way seems preferable to editing and cluttering old code with annotations.
There is also Program.implements() which is probably good to use.
On Jan 12, 2011, at 1:44 PM, Johan Björklund wrote:
There is no real need for this when it is so easy to look into objects, iterate, etc.
While it is true that it's simple to inspect things, I don't know I'd go so far as to say what Cohen's suggesting wouldn't be highly useful. There's something to be said for not having to "roll your own" every time you want to exchange data.
A few years ago I brought up the idea of adding the ability to add metadata to a class or its members, much like "they" do it in .NET or similar to annotations in Java. While it wouldn't solve the problem on its own, it would make it much simpler for frameworks that actually do this sort of thing to configure themselves without writing a lot of extra code. I envisioned a generic syntax in which metadata could be written inline (perhaps stored as a mapping for each member which has metadata as well as one for the class itself) and methods that enabled code to retrieve the metadata specified for a given class or member.
One might argue that you could do this already, which is true to a certain extent. However, the syntax would be more verbose and the inline aspect would be lost, as would the immutable and somewhat camouflaged nature of the data.
I can think of all kinds of uses for this sort of thing (oh, that and the ability to query a member about it's type, which I think is still pretty tricky to do well). If I recall correctly, there was a little discussion about it but there wasn't much traction at the time. I don't think anyone came out and said it was a bad idea, but that might have been the subtle message.
Does anyone have any thoughts about this?
Bill
Met vriendelijke groet / With kind regards / mit besten Grüßen,
Coen Schalkwijk Software Engineer
coen.schalkwijk@rtl.nl mailto:coen.schalkwijk@rtl.nl
coen@rtlinteractief.nl mailto:coen@rtlinteractief.nl
+31 (0)35 671 8915
Hi All,
Creating the XML is no problem, I build a nice method that easily and neatly builds a typed XML. Now I'm working on the translation back to pike and that's when I ran into some 'issues', having mainly to do with translating XML to an object. Currently I have only basic types in the objects I want to store (arrays/mappings with int/string keys and values) which can easily translate back to the pike equivalents (provided I use some less pretty code for handling mapping and array creation). but I'd like to have the subject of object XML serialization covered before the expected function request arises :)
If, a generic type of, annotation was available/possible, it would be far more easier to accomplish this (/serialization to any type of output) without having to know or store everything about the objects involved.
Greetings,
Coen
On 12-1-2011 19:44, Johan Björklund wrote:
On 12/01/11 17:01, Coen Schalkwijk wrote:
Thanks for your suggestion. Is it possible in pike to do/use/consume something like 'they' do in dotNET:
[XMLNode name="A"] classA{ [XMLNode name="aVar"] string a; [XMLNode name="cookieCount"] int b; }
There is no real need for this when it is so easy to look into objects, iterate, etc.
To map special names to variables, just use a mapping:
mapping XMLNames = ([ classA : ([ "a" : "aVar", "b" : "cookieCount" ]), classB : ([ "a" : "aVar", "b" : "somethingElse" ]) ]);
mapping default_XMLNames = ([ "a" : "aVar" ]);
object o = get_object(); mapping o_xml_names = XMLNames[object_program(o)] || default_XMLNames;
foreach (o; string var_name; mixed val) { string name = o_xml_names[var_name]; if (!name) continue; /* add to xml */ }
This way seems preferable to editing and cluttering old code with annotations.
There is also Program.implements() which is probably good to use.
Another problem is that 'string s;' or 'string s=0;' evaluate to 'int' when using %t and 'zero_type()' doesn't help either.
Not a problem for pike but for any other language using the generated XML.
Coen
On 13-1-2011 9:25, Coen Schalkwijk wrote:
Hi All,
Creating the XML is no problem, I build a nice method that easily and neatly builds a typed XML. Now I'm working on the translation back to pike and that's when I ran into some 'issues', having mainly to do with translating XML to an object. Currently I have only basic types in the objects I want to store (arrays/mappings with int/string keys and values) which can easily translate back to the pike equivalents (provided I use some less pretty code for handling mapping and array creation). but I'd like to have the subject of object XML serialization covered before the expected function request arises :)
If, a generic type of, annotation was available/possible, it would be far more easier to accomplish this (/serialization to any type of output) without having to know or store everything about the objects involved.
Greetings,
Coen
On 12-1-2011 19:44, Johan Björklund wrote:
On 12/01/11 17:01, Coen Schalkwijk wrote:
Thanks for your suggestion. Is it possible in pike to do/use/consume something like 'they' do in dotNET:
[XMLNode name="A"] classA{ [XMLNode name="aVar"] string a; [XMLNode name="cookieCount"] int b; }
There is no real need for this when it is so easy to look into objects, iterate, etc.
To map special names to variables, just use a mapping:
mapping XMLNames = ([ classA : ([ "a" : "aVar", "b" : "cookieCount" ]), classB : ([ "a" : "aVar", "b" : "somethingElse" ]) ]);
mapping default_XMLNames = ([ "a" : "aVar" ]);
object o = get_object(); mapping o_xml_names = XMLNames[object_program(o)] || default_XMLNames;
foreach (o; string var_name; mixed val) { string name = o_xml_names[var_name]; if (!name) continue; /* add to xml */ }
This way seems preferable to editing and cluttering old code with annotations.
There is also Program.implements() which is probably good to use.
Another problem is that 'string s;' or 'string s=0;' evaluate to 'int' when using %t and 'zero_type()' doesn't help either.
Not a problem for pike but for any other language using the generated XML.
As a workaround, have you considered using typeof()/_typeof() ?
----8<----8<----8<----
string s; string t=0; string u=""; string v="foo"; zero_type(s);
(1) Result: 0
zero_type(t);
(2) Result: 0
zero_type(u);
(3) Result: 0
zero_type(v);
(4) Result: 0
typeof(s);
(5) Result: string
typeof(t);
(6) Result: string
typeof(u);
(7) Result: string
typeof(v);
(8) Result: string
_typeof(s);
(9) Result: zero
_typeof(t);
(10) Result: zero
_typeof(u);
(11) Result: string
_typeof(v);
(12) Result: string ---->8---->8---->8----
Thank you Bertrand, this helps me a lot!
It seems that comparing to zero is a bit tricky. I only get results with
string s; // or string s="lolcat"; _typeof(s) == _typeof(0);
Is there a neater way to do this?
Met vriendelijke groet / With kind regards / mit besten Grüßen,
Coen Schalkwijk Software Engineer
coen.schalkwijk@rtl.nl mailto:coen.schalkwijk@rtl.nl
coen@rtlinteractief.nl mailto:coen@rtlinteractief.nl
+31 (0)35 671 8915
On 13-1-2011 15:21, Bertrand LUPART wrote:
Another problem is that 'string s;' or 'string s=0;' evaluate to 'int' when using %t and 'zero_type()' doesn't help either.
Not a problem for pike but for any other language using the generated XML.
As a workaround, have you considered using typeof()/_typeof() ?
----8<----8<----8<----
string s; string t=0; string u=""; string v="foo"; zero_type(s);
(1) Result: 0
zero_type(t);
(2) Result: 0
zero_type(u);
(3) Result: 0
zero_type(v);
(4) Result: 0
typeof(s);
(5) Result: string
typeof(t);
(6) Result: string
typeof(u);
(7) Result: string
typeof(v);
(8) Result: string
_typeof(s);
(9) Result: zero
_typeof(t);
(10) Result: zero
_typeof(u);
(11) Result: string
_typeof(v);
(12) Result: string ---->8---->8---->8----
Pity that a zero integer value also results in a zero type:
int t; _typeof(t);
zero
t=0; _typeof(t);
zero
t=2; _typeof(t);
int(2..2)
But I'm glad it works fine for 'true' objects :)
On 13-1-2011 15:21, Bertrand LUPART wrote:
Another problem is that 'string s;' or 'string s=0;' evaluate to 'int' when using %t and 'zero_type()' doesn't help either.
Not a problem for pike but for any other language using the generated XML.
As a workaround, have you considered using typeof()/_typeof() ?
----8<----8<----8<----
string s; string t=0; string u=""; string v="foo"; zero_type(s);
(1) Result: 0
zero_type(t);
(2) Result: 0
zero_type(u);
(3) Result: 0
zero_type(v);
(4) Result: 0
typeof(s);
(5) Result: string
typeof(t);
(6) Result: string
typeof(u);
(7) Result: string
typeof(v);
(8) Result: string
_typeof(s);
(9) Result: zero
_typeof(t);
(10) Result: zero
_typeof(u);
(11) Result: string
_typeof(v);
(12) Result: string ---->8---->8---->8----
...bumped right into a new problem:
mapping(string:mixed) map = ([]); string s; map["test_null"] = s; _typeof(map["test_null"]);
zero
which is fine by me, but:
typeof(map["test_null"]);
mixed
which is not so nice :( and if the variable s has a value:
map["test_null"] = "no_so_null"; typeof(map["test_null"]);
mixed
but then: _ typeof(map["test_null"]);
string
Am I asking something extremely stupid if I'd like to know if it's possible to determine the (original) type of the string in the mapping?
On 13-1-2011 15:21, Bertrand LUPART wrote:
Another problem is that 'string s;' or 'string s=0;' evaluate to 'int' when using %t and 'zero_type()' doesn't help either.
Not a problem for pike but for any other language using the generated XML.
As a workaround, have you considered using typeof()/_typeof() ?
----8<----8<----8<----
string s; string t=0; string u=""; string v="foo"; zero_type(s);
(1) Result: 0
zero_type(t);
(2) Result: 0
zero_type(u);
(3) Result: 0
zero_type(v);
(4) Result: 0
typeof(s);
(5) Result: string
typeof(t);
(6) Result: string
typeof(u);
(7) Result: string
typeof(v);
(8) Result: string
_typeof(s);
(9) Result: zero
_typeof(t);
(10) Result: zero
_typeof(u);
(11) Result: string
_typeof(v);
(12) Result: string ---->8---->8---->8----
On Fri, Jan 14, 2011 at 10:42:52AM +0100, Coen Schalkwijk wrote:
...bumped right into a new problem:
mapping(string:mixed) map = ([]); string s; map["test_null"] = s; _typeof(map["test_null"]);
zero
which is fine by me, but:
typeof(map["test_null"]);
mixed
which is not so nice :( and if the variable s has a value:
why?
map["test_null"] = "no_so_null"; typeof(map["test_null"]);
mixed
but then: _ typeof(map["test_null"]);
string
this is the expected behaviour. typeof() gives the type of the variable which you above defined as mixed. _typeof() gives the type of the value, which, as we can see, is a string.
Am I asking something extremely stupid if I'd like to know if it's possible to determine the (original) type of the string in the mapping?
what do you mean by original type?
greetings, martin.
Hi Martin,
I have a mapping containing different kind of objects. In order to succesfully deserialize any object. I need to know the 'original' type of the object to put in the XML so that the receiving/deserializing language knows whether 1 is a string or an int.
As long as the object has a value, there's no problem, but when a string is NULL, the receiving/deserializing language might still want to know the type, Especially if it concerns a 'custom' class definition.
If I store a NULL instance of MyClass, I'd like to know it was of type MyClass and not 'mixed'.
Does this clarify my problem?
On 14-1-2011 11:27, Martin Bähr wrote:
On Fri, Jan 14, 2011 at 10:42:52AM +0100, Coen Schalkwijk wrote:
...bumped right into a new problem:
mapping(string:mixed) map = ([]); string s; map["test_null"] = s; _typeof(map["test_null"]);
zero
which is fine by me, but:
typeof(map["test_null"]);
mixed
which is not so nice :( and if the variable s has a value:
why?
map["test_null"] = "no_so_null"; typeof(map["test_null"]);
mixed
but then: _ typeof(map["test_null"]);
string
this is the expected behaviour. typeof() gives the type of the variable which you above defined as mixed. _typeof() gives the type of the value, which, as we can see, is a string.
Am I asking something extremely stupid if I'd like to know if it's possible to determine the (original) type of the string in the mapping?
what do you mean by original type?
greetings, martin.
On Fri, Jan 14, 2011 at 11:39:21AM +0100, Coen Schalkwijk wrote:
I have a mapping containing different kind of objects. In order to succesfully deserialize any object. I need to know the 'original' type of the object to put in the XML so that the receiving/deserializing language knows whether 1 is a string or an int.
as far as i can tell you are getting that information.
mapping(string:mixed) map = ([]);
you are declaring that the type of the value is mixed, and typeof() is telling you exactly that:
typeof(map["test_null"]);
mixed
what other information did you expect here?
greetings, martin.
Hi,
I was hoping I'd get 'string' for the type... Now that I've thought it over a bit more: there's no need to know the type of a NULL object in order to deserialize. Doh. You don't need an object to create a NULL. <facepalm> I guess I'm just a bit overactive today :)
Thanks anyway for the help, especially on typeof/_typeof/zero_type.
Coen On 14-1-2011 12:35, Martin Bähr wrote:
On Fri, Jan 14, 2011 at 11:39:21AM +0100, Coen Schalkwijk wrote:
I have a mapping containing different kind of objects. In order to succesfully deserialize any object. I need to know the 'original' type of the object to put in the XML so that the receiving/deserializing language knows whether 1 is a string or an int.
as far as i can tell you are getting that information.
mapping(string:mixed) map = ([]);
you are declaring that the type of the value is mixed, and typeof() is telling you exactly that:
typeof(map["test_null"]);
mixed
what other information did you expect here?
greetings, martin.
Not only do you not need 'string' to recreate a NULL, but there is nothing 'string' about map["test_null"].
* Variables have types. These can be examined with typeof(). * Values have types. These can be examed with _typeof(). * Variables contains values.
That's all there is. A value does not keep a log of variables it has been stored in, or their types. Consider the following code:
string a; mixed b=3; b=a;
You have two variables, a and b. There types are "string" and "mixed", because that's what you declared them to be. The variable types are properties of the variables themselves, and unrelated to the value stored in them (except that it limits the types of values that you are allowed to store there). The typeof() function can in fact be evaluated on a variable that isn't even instantiated (such as during compilation), and thus does not contain a value at all.
Now, let's consider the values during execution. The variable "a" is uninitialized, and thus contains the "zero" value. If you evaluate a, and call _typeof() on the result, it will return "zero". Because that's the type of this value. It is not, has never been, and will never be a string. The variable "a" can be used to store values of type "string", but it doesn't do so now. For "a" to evaluate to a value of type "string", you need to store such a value in it. Evaluating a variable simple fetches the value stored there, it doesn't alter its type in any way.
The variable b is initialized to "3". So if you evaluate b at this point, and call _typeof() on the result, you will get "int(3..3)". This is the type of the value "3", and has nothing to do with the variable b itself. You just get the 3, and look at its type.
Finally, b is assigned a new value. The expression producing the value is a variable access to "a", so the zero value is fetched from variable "a". It's just a value, and has no connection to "a". The zero value thus computed is then stored in "b". If "b" is evaluated, the resulting value will now be the zero, and if you call _typeof() on it, the result will be "zero". Neither "b", nor the value store in it, has anything to do with strings (well, except that "mixed" is a supertype of "string"), so there is no reason why any type function should return "string".
Now, if you're dealing with introspection, you might want to somehow internalize the fact that "variable a is of type string and contains zero". And that's perfectly fine. But then you need to keep in mind that the variable type and value are two separate features of the variable, and so you need to internalize them separately. You can not magically conjure one up from the other. So what you'd need to do is not make a mapping ([ "x":obj->x ]), but rather ([ "x":({typeof(obj->x),obj->x}) ]). Note also that since typeof() operates on declared types, obj needs to be declared with the actual type of object (as opposed to "object") for this to work.
But that's just if the declared type of variables are actually relevant to the algorithm somehow, of course. And in your case it didn't seem to be.
On Fri, Jan 14, 2011 at 01:47:26PM +0100, Coen Schalkwijk wrote:
I was hoping I'd get 'string' for the type...
you can not get string if the variable is defined with mixed:
mapping(string:mixed) map = ([]);
if you define it as mapping(string:string) map = ([]); then typeof() would give you string as a result.
Now that I've thought it over a bit more: there's no need to know the type of a NULL object in order to deserialize.
well, you need the type of a variable in order to recreate the variable with the same type.
greetings, martin.
On Wed, Jan 12, 2011 at 02:15:17PM +0100, Coen Schalkwijk wrote:
Yes, for example (a very naive one); from a pike string "hello world" to <string>hello world</string>
xmlrpc has something like that for the basic types, even functions but not arbitrary objects, though maybe it is enough for you to extend...
greetings, martin.
string encode_xml(mixed data) { string ret = "<pikedata>"; foreach( encode_value(data);; int c ) ret += sprintf("<%d/>", c); return ret + "</pikedata>"; }
On Wed, Jan 12, 2011 at 02:30:22PM +0000, Martin Nilsson (Opera Mini - AFK!) @ Pike (-) developers forum wrote:
string encode_xml(mixed data) { string ret = "<pikedata>"; foreach( encode_value(data);; int c ) ret += sprintf("<%d/>", c); return ret + "</pikedata>"; }
but encode_value is pike specific so not useful for sharing data with non-pike sysyems.
greetings, martin.
Yup and I really need to share this data :/
Coen
On 12-1-2011 15:36, Martin Baehr wrote:
On Wed, Jan 12, 2011 at 02:30:22PM +0000, Martin Nilsson (Opera Mini - AFK!) @ Pike (-) developers forum wrote:
string encode_xml(mixed data) { string ret = "<pikedata>"; foreach( encode_value(data);; int c ) ret += sprintf("<%d/>", c); return ret + "</pikedata>"; }
but encode_value is pike specific so not useful for sharing data with non-pike sysyems.
greetings, martin.
pike-devel@lists.lysator.liu.se