qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Andrea Bolognani <abologna@redhat.com>
Cc: Victor Toso <victortoso@redhat.com>,
	qemu-devel@nongnu.org, John Snow <jsnow@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Subject: Re: [RFC PATCH v1 0/8] qapi: add generator for Golang interface
Date: Tue, 10 May 2022 19:02:21 +0100	[thread overview]
Message-ID: <YnqorSdh1pOmMDN0@redhat.com> (raw)
In-Reply-To: <CABJz62MiVBMP-VDYkGJe+eLf6GXnifFYo-5D2_-DUwP1uY8yWg@mail.gmail.com>

On Tue, May 10, 2022 at 01:37:50PM -0400, Andrea Bolognani wrote:
> On Mon, May 09, 2022 at 12:21:10PM +0200, Victor Toso wrote:
> > On Tue, Apr 19, 2022 at 11:12:28AM -0700, Andrea Bolognani wrote:
> > > Based on the example you have in the README and how commands are
> > > defined, invoking (a simplified version of) the trace-event-get-state
> > > command would look like
> > >
> > >   cmd := Command{
> > >       Name: "trace-event-get-state",
> > >       Arg: TraceEventGetStateCommand{
> > >           Name: "qemu_memalign",
> > >       },
> > >   }

Note there is clear redundancy here between 'Name' and the struct
type. IMHO the better approach would be

       cmd := TraceEventGetStateCommand{
          Name: 'qemu_memalign'
       }

and have 'Command' simply as an interface that TraceEventGetStateCommand
implements. I don't think the interface would need more than a
Marshal and Demarshal method, which serialize the 'Arg' and then add
the Name field explicitly. 


> > >   qmp_input, _ := json.Marshal(&cmd)
> > >   // qmp_input now contains
> > >   //   {"execute":"trace-event-get-state","arguments":{"name":"qemu_memalign"}}
> > >   // do something with it
> > >
> > >   qmp_output :=
> > > ([]byte)(`{"return":{"name":"qemu_memalign","state":"disabled"}}`)
> > >   ret := cmd.GetReturnType()
> > >   _ = json.Unmarshal(qmp_output, &ret)
> > >   // ret is a CommandResult instance whose Value member can be cast
> > >   // to a TraceEventInfo struct
> > >
> > > First of all, from an application's point of view there are way too
> > > many steps involved:
> >
> > It can actually get worse. I've used a lot of nested struct to
> > define a Base type for a given Type. In Go, If you try to
> > initialize a Type that has a nested Struct, you'll need to use
> > the nested struct Type as field name and this is too verbose.
> >
> > See https://github.com/golang/go/issues/29438 (merged with:
> > https://github.com/golang/go/issues/12854)
> >
> > The main reason that I kept it is because it maps very well with
> > the over-the-wire protocol.
> 
> Right, I had not realized how bad things really were :)
> 
> I've noticed the use of base types and while I didn't bring it up in
> my initial message because the other concerns seemed of much higher
> importance, I actually wondered whether we need to expose them to
> users of the Go SDK.
> 
> I think we should flatten things. That's what happens with the C
> generator already, for example in
> 
>   struct InetSocketAddress {
>       /* Members inherited from InetSocketAddressBase: */
>       char *host;
>       char *port;
>       /* Own members: */
>       bool has_numeric;
>       bool numeric;
>       /* ... */
>   };
> 
> This representation mirrors the wire protocol perfectly, so I see no
> reason not to adopt it. Am I missing something?

The main reason not to flatten is if you have scenarios where it is
useful to work against the base type directly. I'm not sure that we
have such a need though.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2022-05-10 18:03 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-01 22:40 [RFC PATCH v1 0/8] qapi: add generator for Golang interface Victor Toso
2022-04-01 22:40 ` [RFC PATCH v1 1/8] qapi: golang: Generate qapi's enum types in Go Victor Toso
2022-05-10 10:06   ` Daniel P. Berrangé
2022-05-10 11:15     ` Victor Toso
2022-05-10 11:19       ` Daniel P. Berrangé
2022-05-10 11:28         ` Victor Toso
2022-05-10 11:39           ` Daniel P. Berrangé
2022-04-01 22:40 ` [RFC PATCH v1 2/8] qapi: golang: Generate qapi's alternate " Victor Toso
2022-05-10 10:10   ` Daniel P. Berrangé
2022-05-10 11:21     ` Victor Toso
2022-05-10 11:28       ` Daniel P. Berrangé
2022-04-01 22:40 ` [RFC PATCH v1 3/8] qapi: golang: Generate qapi's struct " Victor Toso
2022-04-01 22:41 ` [RFC PATCH v1 4/8] qapi: golang: Generate qapi's union " Victor Toso
2022-05-10 10:26   ` Daniel P. Berrangé
2022-05-10 11:32     ` Victor Toso
2022-05-10 11:42       ` Daniel P. Berrangé
2022-04-01 22:41 ` [RFC PATCH v1 5/8] qapi: golang: Generate qapi's event " Victor Toso
2022-05-10 10:42   ` Daniel P. Berrangé
2022-05-10 11:38     ` Victor Toso
2022-04-01 22:41 ` [RFC PATCH v1 6/8] qapi: golang: Generate qapi's command " Victor Toso
2022-04-01 22:41 ` [RFC PATCH v1 7/8] qapi: golang: Add CommandResult type to Go Victor Toso
2022-04-01 22:41 ` [RFC PATCH v1 8/8] qapi: golang: document skip function visit_array_types Victor Toso
2022-04-19 18:12 ` [RFC PATCH v1 0/8] qapi: add generator for Golang interface Andrea Bolognani
2022-04-19 18:42   ` Andrea Bolognani
2022-04-28 13:50   ` Markus Armbruster
2022-04-29 13:15     ` Andrea Bolognani
2022-05-02  7:21       ` Markus Armbruster
2022-05-02  9:04         ` Andrea Bolognani
2022-05-02 11:46           ` Markus Armbruster
2022-05-02 14:01             ` Andrea Bolognani
2022-05-03  7:57               ` Markus Armbruster
2022-05-03  9:40                 ` Andrea Bolognani
2022-05-03 11:04                   ` Kevin Wolf
2022-05-10  9:55                   ` Daniel P. Berrangé
2022-05-11  6:15                   ` Markus Armbruster
2022-05-09 18:53               ` Victor Toso
2022-05-10  8:06                 ` Markus Armbruster
2022-05-10 11:48                   ` Victor Toso
2022-05-10  9:52               ` Daniel P. Berrangé
2022-05-10 15:25                 ` Andrea Bolognani
2022-05-11 13:45                 ` Markus Armbruster
2022-05-09 10:21   ` Victor Toso
2022-05-10 17:37     ` Andrea Bolognani
2022-05-10 18:02       ` Daniel P. Berrangé [this message]
2022-04-26 11:14 ` Markus Armbruster
2022-05-09 10:52   ` Victor Toso
2022-05-10  8:53   ` Daniel P. Berrangé
2022-05-10  9:06     ` Victor Toso
2022-05-10  9:17       ` Daniel P. Berrangé
2022-05-10  9:32         ` Daniel P. Berrangé
2022-05-10 10:50           ` Victor Toso
2022-05-10 10:57             ` Daniel P. Berrangé
2022-05-10 12:02     ` Markus Armbruster
2022-05-10 12:34       ` Daniel P. Berrangé
2022-05-10 12:51         ` Daniel P. Berrangé
2022-05-11 14:17           ` Markus Armbruster
2022-05-11 14:41             ` Daniel P. Berrangé
2022-05-11 15:38           ` Andrea Bolognani
2022-05-11 15:50             ` Daniel P. Berrangé
2022-05-11 16:22               ` Andrea Bolognani
2022-05-11 16:32                 ` Daniel P. Berrangé
2022-05-18  8:10               ` Victor Toso
2022-05-18  8:51                 ` Daniel P. Berrangé
2022-05-18  9:01                   ` Victor Toso
2022-05-11 14:17         ` Markus Armbruster
2022-05-18  8:55           ` Victor Toso
2022-05-18 12:30             ` Markus Armbruster
2022-05-25 13:49               ` Andrea Bolognani
2022-05-25 14:10                 ` Markus Armbruster
2022-06-01 13:53                 ` Victor Toso
2022-05-10 10:47 ` Daniel P. Berrangé

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=YnqorSdh1pOmMDN0@redhat.com \
    --to=berrange@redhat.com \
    --cc=abologna@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=victortoso@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).