qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 3/8] Add QBuffer


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 3/8] Add QBuffer
Date: Sun, 16 May 2010 19:12:28 -0500

On Sun, May 16, 2010 at 12:38 PM, Jamie Lokier <address@hidden> wrote:
> Anthony Liguori wrote:
>> Instead of encoding just as a string, it would be a good idea to encode
>> it as something like:
>>
>> {'__class__': 'base64', 'data': ...}
>
> Is there a benefit to the class indirection, over simply a keyword?:
>
> {'__base64__': ...}
>
> __class__ seems to suggest much more than it's being used for here.

Yes.  The problem with JSON is that it's based on JavaScript and
JavaScript is goofy :-)

JavaScript's object mechanism doesn't map well to most other languages
since it's prototype based.  What we're calling QDict's are really
objects in JavaScript and they carry mostly no type information.  With
JS, it's very simple to treat a generic object as a specialized class
after instantiation which means objects don't need type information.

For non-prototype languages, which is the vast majority of clients,
it's necessary to have type information at instantiation time since
monkey patching is awkward at best.  That's why we need a special,
reserved, object member to carry type information.  The remainder of
the object members represent the serialized state of the object.

Another way to think of it, is that we're already transmitting objects
so we really just need a way to say, no, this isn't just a Dictionary,
it's really an instance of the following class.

Regards,

Anthony Liguori

> -- Jamie
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]