[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20170807091258.7c70ff87@xeon-e3>
Date: Mon, 7 Aug 2017 09:12:58 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: Julien Fortin <julien@...ulusnetworks.com>
Cc: netdev@...r.kernel.org, roopa@...ulusnetworks.com,
nikolay@...ulusnetworks.com, dsa@...ulusnetworks.com
Subject: Re: [PATCH 05/27] ip: ipaddress.c: add support for json output
On Thu, 3 Aug 2017 17:54:53 +0200
Julien Fortin <julien@...ulusnetworks.com> wrote:
> From: Julien Fortin <julien@...ulusnetworks.com>
>
> This patch converts all output (mostly fprintfs) to the new ip_print api
> which handle both regular and json output.
> Initialize a json_writer and open an array object if -json was specified.
> Note that the JSON attribute naming follows the NETLINK_ATTRIBUTE naming.
>
> In many places throughout the code, IP, matches integer values with
> hardcoded strings tables, such as link mode, link operstate or link
> family.
> In JSON context, this will result in a named string field. In the
> very unlikely event that the requested index is out of bound, IP
> displays the raw integer value. For JSON context this result in
> having a different integer field example bellow:
>
> if (mode >= ARRAY_SIZE(link_modes))
> print_int(PRINT_ANY, "linkmode_index", "mode %d ", mode);
> else
> print_string(PRINT_ANY, "linkmode", "mode %s ",
> link_modes[mode]);
>
> The "_index" suffix is open to discussion and it is something that I came
> up with. The bottom line is that you can't have a string field that may
> become an int field in specific cases. Programs written in strongly type
> languages (like C) might break if they are expecting a string value and
> got an integer instead. We don't want to confuse anybody or make the code
> even more complicated handling these specifics cases.
> Hence the extra "_index" field that is easy to check for and deal with.
>
This patch does not apply to current master branch.
Please rebase.
Powered by blists - more mailing lists