From 04a06f9b188c161cdc5a68ad71cb5dda0606dec5 Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Fri, 28 Oct 2016 13:13:25 +0200 Subject: [PATCH] json: support multi-dimensional arrays of char Now member like char fArr[2][3][4] will be coded into JSON string "fArr" : [["0123", "1234", "2345"], ["1234", "2345", "3456"]] Signed-off-by: Sergey Linev --- io/io/src/TBufferJSON.cxx | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/io/io/src/TBufferJSON.cxx b/io/io/src/TBufferJSON.cxx index 3a3174ac4078d..6088bed68b803 100644 --- a/io/io/src/TBufferJSON.cxx +++ b/io/io/src/TBufferJSON.cxx @@ -2302,15 +2302,35 @@ void TBufferJSON::WriteFastArray(const Bool_t *b, Int_t n) void TBufferJSON::WriteFastArray(const Char_t *c, Int_t n) { - Bool_t asarray = fExpectedChain; - if (Stack(0)->fElem != 0) - if (Stack(0)->fElem->GetType() == TStreamerInfo::kOffsetP + TStreamerInfo::kChar) asarray = kTRUE; + TStreamerElement* el = Stack(0)->fElem; - if (asarray) { + if (fExpectedChain || (el && (el->GetType() == TStreamerInfo::kOffsetP + TStreamerInfo::kChar))) { TBufferJSON_WriteFastArray(c); - } else { + } else + if (!el || (el->GetArrayDim() < 2) || (el->GetArrayLength() != n)) { + // write as simple const char TJSONPushValue(); JsonWriteConstChar(c, n); + } else { + // write as multi-dim array of strings + TJSONPushValue(); + TArrayI indexes(el->GetArrayDim() - 1); + indexes.Reset(0); + Int_t cnt = 0, shift = 0, len = el->GetMaxIndex(indexes.GetSize()); + while (cnt >= 0) { + if (indexes[cnt] >= el->GetMaxIndex(cnt)) { + fValue.Append("]"); + indexes[cnt--] = 0; + if (cnt >= 0) indexes[cnt]++; + continue; + } + fValue.Append(indexes[cnt] == 0 ? "[" : fArraySepar.Data()); + if (++cnt == indexes.GetSize()) { + JsonWriteConstChar(c+shift*len, len); + indexes[--cnt]++; + shift++; + } + } } }