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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "tools/battor_agent/serial_utils.h"
6
7 namespace battor {
8
9 std::string CharVectorToString(const std::vector<char> data) {
10 std::string s;
11
12 // Reserve enough bytes for '0x', the two data characters, a space, and a null
13 // terminating byte.
14 char num_buff[6];
15 for (char d : data) {
16 // We use sprintf because stringstream's hex support wants to print our
17 // characters as signed.
18 sprintf(num_buff, "0x%02hhx ", d);
19 s += num_buff;
20 }
21
22 return s.substr(0, s.size() - 1);
23 }
24
25 std::string CharArrayToString(const char* bytes, size_t len) {
26 return CharVectorToString(std::vector<char>(bytes, bytes + len));
27 }
28
29 } // namespace battor
OLDNEW
« 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