From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:43041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAjj5-0000mE-DJ for qemu-devel@nongnu.org; Mon, 03 Oct 2011 10:42:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RAjj4-0007Jg-B8 for qemu-devel@nongnu.org; Mon, 03 Oct 2011 10:42:39 -0400 Received: from e5.ny.us.ibm.com ([32.97.182.145]:40027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAjj4-0007JS-8G for qemu-devel@nongnu.org; Mon, 03 Oct 2011 10:42:38 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by e5.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p93EBBer010189 for ; Mon, 3 Oct 2011 10:11:11 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p93Eg4hN1482908 for ; Mon, 3 Oct 2011 10:42:04 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p93Eg4ON013681 for ; Mon, 3 Oct 2011 10:42:04 -0400 Message-ID: <4E89C9BA.8070404@us.ibm.com> Date: Mon, 03 Oct 2011 09:42:02 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1316443309-23843-1-git-send-email-mdroth@linux.vnet.ibm.com> <20111003064653.GA15380@redhat.com> <4E89AFB4.8000103@us.ibm.com> <20111003132445.GB18920@redhat.com> <4E89BC1A.30208@codemonkey.ws> <20111003141140.GB19689@redhat.com> In-Reply-To: <20111003141140.GB19689@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC] New Migration Protocol using Visitor Interface List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: aliguori@linux.vnet.ibm.com, Michael Roth , qemu-devel@nongnu.org On 10/03/2011 09:11 AM, Michael S. Tsirkin wrote: > On Mon, Oct 03, 2011 at 08:43:54AM -0500, Anthony Liguori wrote: >>>> visit_start_array(v, "entries", errp); >>>> for (int i = 0; i< s->size; i++) { >>>> visit_type_int(v, NULL,&s->entry[i], errp); >>>> } >>>> visit_end_array(v, errp); >>> >>> Sequences can encode structures not just arrays. >>> How would you encode this for example: >>> >>> SEQUENCE OF { VQN: INTEGER, SEQUENCE { OPTIONAL VECTOR: INTEGER} } >> >> visit_start_array(v, "vqs", errp); >> for (i = 0; i< s->n_vqs; i++) { >> // Array elements never have a name, hence NULL name >> visit_start_struct(v, "VirtQueue", NULL, errp); >> visit_type_int(v,&s->vq[i].num, "vqn", errp); >> >> // Given this sub-struct an arbitrary name. It could also be anonymous. >> visit_start_struct(v, "MsixInfo", "msix_info", errp); >> if (s->vq[i].msix_enabled) { >> visit_type_int(v,&s->vq[i].vector, "vector", errp); > > Why is this a pointer to vector, btw? So you can write a single visit function that works for input or output. Think of the simple case like: void visit_simple_type(Visitor *v, SimpleType *t, const char *name, Error **errp) { visit_start_struct(v, "SimpleType", name, errp); visit_type_int(v, &t->a, "a", errp); visit_type_int(v, &t->b, "b", errp); visit_end_struct(v, errp); } For complex types like Virtio, you need to do a bit more. You wouldn't do a simple for () {} loop but instead use the Visitor list mechanism. That would eliminate the need to have to marshal n_vqs. > >> } >> visit_end_struct(v, errp); >> >> visit_end_struct(v, errp); >> } >> visit_end_array(v, errp); >> >> This would also generate JSON of: >> >> 'vqs': [ { 'vqn': 2, 'msix_info': { 'vector': 3 } } ] > > How would optional fields be handled? As far as the Visitor goes, if something is optional you just don't encode it. If you need to key off the presence of a field, presumably you could just check to see whether it succeeded or failed to visit that field. I'm not 100% sure if you can do a single input/output visitor when you have optional fields. My rough thinking is that each device would have a input/output visitor callback that took the same signature. That gives the flexibility of having two separate interfaces but in the common case, you just pass the same function for both. > Specifically > the case where first field in a sequence tells > you the meaning of the following ones? Can you give me the example in ASN.1? Regards, Anthony Liguori