Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: tools/battor_agent/serial_utils.cc

Issue 1966413002: [battor agent] Move code for stringifying bytes into a util file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed signed/unsigned char problems Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/battor_agent/serial_utils.h ('k') | tools/battor_agent/serial_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/battor_agent/serial_utils.cc
diff --git a/tools/battor_agent/serial_utils.cc b/tools/battor_agent/serial_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a40a333dac1fef501f6fe8c1022d46298dc1a0a4
--- /dev/null
+++ b/tools/battor_agent/serial_utils.cc
@@ -0,0 +1,29 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tools/battor_agent/serial_utils.h"
+
+namespace battor {
+
+std::string CharVectorToString(const std::vector<char> data) {
+ std::string s;
+
+ // Reserve enough bytes for '0x', the two data characters, a space, and a null
+ // terminating byte.
+ char num_buff[6];
+ for (char d : data) {
+ // We use sprintf because stringstream's hex support wants to print our
+ // characters as signed.
+ sprintf(num_buff, "0x%02hhx ", d);
+ s += num_buff;
+ }
+
+ return s.substr(0, s.size() - 1);
+}
+
+std::string CharArrayToString(const char* bytes, size_t len) {
+ return CharVectorToString(std::vector<char>(bytes, bytes + len));
+}
+
+} // namespace battor
« no previous file with comments | « tools/battor_agent/serial_utils.h ('k') | tools/battor_agent/serial_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698