From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CDDEBA09E8; Wed, 19 Oct 2022 20:08:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C8C742BF9; Wed, 19 Oct 2022 20:08:56 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 4152742BE9 for ; Wed, 19 Oct 2022 20:08:55 +0200 (CEST) X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH] telemetry: support boolean type Date: Wed, 19 Oct 2022 20:08:53 +0200 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D8741A@smartserver.smartshare.dk> In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH] telemetry: support boolean type Thread-Index: Adjj2pbrZirVp5ReRrGL+PGTozchmwACsCUg References: <20221019073702.3948624-1-david.marchand@redhat.com> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Bruce Richardson" , "David Marchand" Cc: , "Ciara Power" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: Bruce Richardson [mailto:bruce.richardson@intel.com] > Sent: Wednesday, 19 October 2022 18.48 >=20 > On Wed, Oct 19, 2022 at 04:28:58PM +0200, David Marchand wrote: > > On Wed, Oct 19, 2022 at 3:48 PM Bruce Richardson > > wrote: > > > > > > On Wed, Oct 19, 2022 at 09:37:02AM +0200, David Marchand wrote: > > > > Add the boolean type RTE_TEL_BOOL_VAL for values in arrays and > dicts. > > > > > > > > Signed-off-by: David Marchand > > > > --- [...] > > > > +/* Appends a boolean into the JSON array in the provided = buffer. > */ > > > > +static inline int > > > > +rte_tel_json_add_array_bool(char *buf, const int len, const int > used, > > > > + bool val) > > > > +{ > > > > + int ret, end =3D used - 1; /* strip off final delimiter */ > > > > + if (used <=3D 2) /* assume empty, since minimum is '[]' */ > > > > + return __json_snprintf(buf, len, "[%s]", > > > > + val ? "true" : "false"); > > > > + > > > > + ret =3D __json_snprintf(buf + end, len - end, ",%s]", > > > > + val ? "true" : "false"); > > > > > > Wonder if it's worthwhile doing a macro for this conditional, = since > the > > > same ternary-operator snippet appears 4 times in this code. > > > > Err, naming it would be hard and I don't see for now how we could > reuse it. > > > Yes, and I see Morten has objected from a readability perspective, so > keeping as-is is fine. >=20 > One final suggestion though might be to have an array with the strings > as so: >=20 > const char *bool_str[2] =3D { "false", "true" }; >=20 > and then in the code use "bool_str[val]" in place of ternary operator. I don't consider that more readable than the original. > (From a quick check with godbolt is looks like bool params are clamped > to 0 > or 1 on function call, but if we want to be paranoid, we can lookup > based > on [!!val]) >=20 > However, ok to keep code as-is for this too. Thank you, yes, please. >=20 > /Bruce