qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Juan Quintela <quintela@redhat.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
	Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 3/8] Add QBuffer
Date: Mon, 17 May 2010 09:48:45 +0300	[thread overview]
Message-ID: <4BF0E6CD.7090909@redhat.com> (raw)
In-Reply-To: <AANLkTikQXEYnsxNDe31zUCjQ1f2mDZ6NTI_d-kTw4tN-@mail.gmail.com>

On 05/17/2010 03:12 AM, Anthony Liguori wrote:
> On Sun, May 16, 2010 at 12:38 PM, Jamie Lokier<jamie@shareable.org>  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 :-)
>
>    

I suggest completely ignoring JavaScript.  JSON is simply an encoding 
for numbers, strings, arrays, and key-value stores.  Where's the goofiness?

> 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.
>    

The alternative is to have a schema.  Sun RPC/XDR doesn't carry any type 
information (you can't even distinguish between a number and text) yet C 
clients have to problem extracting typed information from it.

Having __class__ everywhere means we're carrying the schema in every 
message instead of just once.

> 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.
>    

Are there cases where the receiver cannot infer this from the context?

As I see it, dynamic type information is easiest for dynamicically typed 
languages.  You just have a dict of class names -> object constructor 
and call the constructors at runtime.  Statically typed languages will 
need a schema to use objects, since the field types have to be known at 
compile time, not just run time.

Another wart is arrays: statically typed languages usually contain only 
objects of the same type, but here this isn't known until we process the 
first member.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

  reply	other threads:[~2010-05-17  6:49 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-14 13:20 [Qemu-devel] [PATCH 0/8] Basic device state visualization Jan Kiszka
2010-05-14 13:20 ` [Qemu-devel] [PATCH 1/8] qdev: Allow device addressing via 'driver.instance' Jan Kiszka
2010-05-18 12:15   ` Markus Armbruster
2010-05-18 12:31     ` Gerd Hoffmann
2010-05-18 12:38       ` [Qemu-devel] " Juan Quintela
2010-05-18 13:06         ` Gerd Hoffmann
2010-05-18 16:54       ` Jan Kiszka
2010-05-19  8:29       ` [Qemu-devel] " Avi Kivity
2010-05-14 13:20 ` [Qemu-devel] [PATCH 2/8] Add base64 encoder/decoder Jan Kiszka
2010-05-14 13:20 ` [Qemu-devel] [PATCH 3/8] Add QBuffer Jan Kiszka
2010-05-14 18:15   ` Anthony Liguori
2010-05-15  8:45     ` [Qemu-devel] " Jan Kiszka
2010-05-15  8:49       ` Avi Kivity
2010-05-15  8:59         ` Jan Kiszka
2010-05-15 17:31           ` Avi Kivity
2010-05-16  9:37             ` Paolo Bonzini
2010-05-16  9:50               ` Avi Kivity
2010-05-16 10:15                 ` Jan Kiszka
2010-05-16 10:16                 ` Paolo Bonzini
2010-05-16 10:49                   ` Avi Kivity
2010-05-16 10:04             ` Jan Kiszka
2010-05-16 17:38     ` [Qemu-devel] " Jamie Lokier
2010-05-16 18:03       ` [Qemu-devel] " Jan Kiszka
2010-05-17 20:20         ` Jamie Lokier
2010-05-17  0:12       ` [Qemu-devel] " Anthony Liguori
2010-05-17  6:48         ` Avi Kivity [this message]
2010-05-17  7:40           ` [Qemu-devel] " Jan Kiszka
2010-05-17  7:45             ` Avi Kivity
2010-05-17  7:57               ` Jan Kiszka
2010-05-17  8:10                 ` Avi Kivity
2010-05-17  8:13                   ` Avi Kivity
2010-05-17  8:55                   ` Jan Kiszka
2010-05-17  8:59                     ` Avi Kivity
2010-05-17  9:17                       ` Jan Kiszka
2010-05-17  9:29                         ` Avi Kivity
2010-05-18 12:27                     ` Markus Armbruster
2010-05-18 17:24                       ` Avi Kivity
2010-05-17 13:05               ` Anthony Liguori
2010-05-18 12:28                 ` Markus Armbruster
2010-05-14 13:20 ` [Qemu-devel] [PATCH 4/8] monitor: Add basic device state visualization Jan Kiszka
2010-05-18 12:12   ` Markus Armbruster
2010-05-18 17:09     ` [Qemu-devel] " Jan Kiszka
2010-05-14 13:20 ` [Qemu-devel] [PATCH 5/8] qmp: Teach basic capability negotiation to python example Jan Kiszka
2010-05-14 13:20 ` [Qemu-devel] [PATCH 6/8] qmp: Fix python helper /wrt long return strings Jan Kiszka
2010-05-14 13:20 ` [Qemu-devel] [PATCH 7/8] Add QLIST_INSERT_TAIL Jan Kiszka
2010-05-16  9:38   ` [Qemu-devel] " Paolo Bonzini
2010-05-16 10:16     ` Jan Kiszka
2010-05-14 13:20 ` [Qemu-devel] [PATCH 8/8] qdev: Add new devices/buses at the tail Jan Kiszka
2010-05-14 16:12 ` [Qemu-devel] Re: [PATCH 0/8] Basic device state visualization Avi Kivity
2010-05-14 16:24   ` Jan Kiszka
2010-05-14 16:38     ` Avi Kivity
2010-05-14 18:16 ` [Qemu-devel] " Anthony Liguori
2010-05-14 18:50 ` Blue Swirl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BF0E6CD.7090909@redhat.com \
    --to=avi@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=anthony@codemonkey.ws \
    --cc=armbru@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).