From 3f4df3addb128f71b7f95d537e931376289d0fcb Mon Sep 17 00:00:00 2001 From: Jeremy Lorelli Date: Tue, 17 Mar 2026 23:07:28 -0700 Subject: [PATCH] Add -S option to pvget/pvmonitor to stringify byte arrays This emulates the behavior of the caget -S option. Byte arrays are displayed as strings. --- src/factory/printer.cpp | 28 ++++++++++++++++++++++++++-- src/pv/pvData.h | 4 ++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/factory/printer.cpp b/src/factory/printer.cpp index 70e81c7..0bd5af8 100644 --- a/src/factory/printer.cpp +++ b/src/factory/printer.cpp @@ -431,12 +431,36 @@ std::ostream& operator<<(std::ostream& strm, const PVStructure::Formatter& forma return strm; case scalarArray: + { strm<(value.get())<<'\n'; - return strm; + const PVScalarArray* pvArray = static_cast(value.get()); + ScalarArrayConstPtr scalarArray = pvArray->getScalarArray(); + + // Stringify byte arrays if requested + if (format.xstring && scalarArray && scalarArray->getElementType() == pvByte) { + shared_vector byteArray; + pvArray->getAs(byteArray); + + const char* str = reinterpret_cast(byteArray.data()); + const size_t slen = strlen(str); + + const size_t buflen = epicsStrnEscapedFromRawSize(str, slen); + + char* buf = new char[buflen+1] {}; + epicsStrnEscapedFromRaw(buf, buflen+1, str, slen); + + strm<