| OLD | NEW |
| (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 |
| OLD | NEW |