blob: ff420f97bbab7058037cd0982844d165ecc5e955 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompsona8d7b062013-08-08 15:56:35 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsona8d7b062013-08-08 15:56:35 -07005 * See COPYING for copyright and distribution information.
6 */
7
8#include <sstream>
Jeff Thompson25b4e612013-10-10 16:03:24 -07009#include <ndn-cpp/common.hpp>
Jeff Thompsona8d7b062013-08-08 15:56:35 -070010
11using namespace std;
12
13namespace ndn {
14
Jeff Thompson0050abe2013-09-17 12:50:25 -070015string
Jeff Thompson10ad12a2013-09-24 16:19:11 -070016toHex(const vector<uint8_t>& array)
Jeff Thompsona8d7b062013-08-08 15:56:35 -070017{
Jeff Thompsonb0948a52013-09-12 14:38:26 -070018 if (!&array)
19 return "";
20
Jeff Thompsona8d7b062013-08-08 15:56:35 -070021 ostringstream result;
22 result.flags(ios::hex | ios::uppercase);
Jeff Thompson97223af2013-09-24 17:01:27 -070023 for (size_t i = 0; i < array.size(); ++i) {
Jeff Thompson10ad12a2013-09-24 16:19:11 -070024 uint8_t x = array[i];
Jeff Thompsona8d7b062013-08-08 15:56:35 -070025 if (x < 16)
26 result << '0';
27 result << (unsigned int)x;
28 }
29
30 return result.str();
31}
32
33}
34