On Thu,  3 Aug 2017 17:54:53 +0200
Julien Fortin <jul...@cumulusnetworks.com> wrote:

> From: Julien Fortin <jul...@cumulusnetworks.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.

Reply via email to