Fix netlink message printer byte counts
Don't print extra byte numbering for arrays with a size that is a
multiple of 16.
Bug: 161938586
Test: Manual inspection of printer output
Change-Id: I4a7948439dd18b440a6abfae388306167433ebd6
diff --git a/automotive/can/1.0/default/libnetdevice/printer.cpp b/automotive/can/1.0/default/libnetdevice/printer.cpp
index 0076dd6..00dc992 100644
--- a/automotive/can/1.0/default/libnetdevice/printer.cpp
+++ b/automotive/can/1.0/default/libnetdevice/printer.cpp
@@ -65,14 +65,13 @@
const auto rawData = data.getRaw();
const auto dataLen = rawData.len();
ss << std::hex;
- if (dataLen > 16) ss << std::endl << " 0000 ";
int i = 0;
for (const auto byte : rawData) {
- if (i++ > 0) ss << ' ';
- ss << std::setw(2) << unsigned(byte);
- if (i % 16 == 0) {
+ if (i % 16 == 0 && dataLen > 16) {
ss << std::endl << ' ' << std::dec << std::setw(4) << i << std::hex;
}
+ if (i++ > 0 || dataLen > 16) ss << ' ';
+ ss << std::setw(2) << unsigned(byte);
}
ss << std::dec;
if (dataLen > 16) ss << std::endl;