Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include <sstream> |
| 8 | #include "common.hpp" |
| 9 | |
| 10 | using namespace std; |
| 11 | |
| 12 | namespace ndn { |
| 13 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 14 | string |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 15 | toHex(const vector<uint8_t>& array) |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 16 | { |
Jeff Thompson | b0948a5 | 2013-09-12 14:38:26 -0700 | [diff] [blame] | 17 | if (!&array) |
| 18 | return ""; |
| 19 | |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 20 | ostringstream result; |
| 21 | result.flags(ios::hex | ios::uppercase); |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 22 | for (size_t i = 0; i < array.size(); ++i) { |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 23 | uint8_t x = array[i]; |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 24 | if (x < 16) |
| 25 | result << '0'; |
| 26 | result << (unsigned int)x; |
| 27 | } |
| 28 | |
| 29 | return result.str(); |
| 30 | } |
| 31 | |
| 32 | } |
| 33 | |