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