Skip to content

Add -S option to pvget/pvmonitor to stringify byte arrays#1

Open
JJL772 wants to merge 1 commit into
slac-8.0.1from
pr-8.0.1-pvget-S-option
Open

Add -S option to pvget/pvmonitor to stringify byte arrays#1
JJL772 wants to merge 1 commit into
slac-8.0.1from
pr-8.0.1-pvget-S-option

Conversation

@JJL772

@JJL772 JJL772 commented May 27, 2026

Copy link
Copy Markdown
Member

This emulates the behavior of the caget -S option. Byte arrays are displayed as strings.

Requires slac-epics/pvAccessCPP#2

@mskoufis

Copy link
Copy Markdown

Some comments so I understand this better.

  • For this check below:
for (shared_vector<const int8_t>::iterator it = byteArray.begin(); it != byteArray.end(); ++it) {
                            if (!*it)
                                break;
                            strm<<static_cast<char>(*it);

What happens if we encounter a legitimate 0x00 byte within the binary data? Does it exit prematurely?

  • Also, are all byte arrays NUL terminated? If not, then this loop may keep on reading passed the array byte content or no?
  • Do we need to consider the case of pvUByte for the byte array or only pvByte? Seems that we convert to characters for pvByte only. Was this the intent?
  • Do we expect to have any special characters in the byte array that shouldn't need to be stringified or may cause printing issues?
  • Do we need to keep the floating point precision if we just print characters?
    strm<<std::setprecision(6);

@JJL772

JJL772 commented May 28, 2026

Copy link
Copy Markdown
Member Author

Also, are all byte arrays NUL terminated? If not, then this loop may keep on reading passed the array byte content or no?

Since it is using an iterator and checking against byteArray.end() it shouldn't overrun.

Do we need to consider the case of pvUByte for the byte array or only pvByte? Seems that we convert to characters for pvByte only. Was this the intent?

This is a good point. Initially I was going to have it apply to pvUByte as well, but looking at the caget code, it only stringifies signed byte arrays on request.

Do we expect to have any special characters in the byte array that shouldn't need to be stringified or may cause printing issues?

This is a good point; perhaps I should escape unprintable chars? Then they'd be printed as \x12 (for example). I'm not sure what the caget code does, and I'd like to match the behavior with that somewhat.

Also worth noting that non-ASCII chars encoded with UTF-8 (or ANY chars encoded with UTF-16/32) will be printed incorrectly. I dont think we have to worry much about encoding though,

Do we need to keep the floating point precision if we just print characters?
strm<<std::setprecision(6);

Good point, I will apply this change

@JJL772

JJL772 commented May 28, 2026

Copy link
Copy Markdown
Member Author

Seems like I can just use epicsStrnEscapedFromRaw, which is what caget uses.

@JJL772 JJL772 force-pushed the pr-8.0.1-pvget-S-option branch from 6aadc55 to 4d470d2 Compare May 29, 2026 00:00
This emulates the behavior of the caget -S option. Byte arrays are
displayed as strings.
@JJL772 JJL772 force-pushed the pr-8.0.1-pvget-S-option branch from 4d470d2 to 3f4df3a Compare May 29, 2026 00:02
@JJL772

JJL772 commented May 29, 2026

Copy link
Copy Markdown
Member Author

@mskoufis this is how it behaves now with unprintable chars:

$ pvget -S mystring
mystring 2026-05-28 16:44:48.472  *@,\x16\n\x02
$ caget -S mystring
mystring *@,\x16\n\x02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants