blob: 31569e3f12ae5442371caefaba25aa8b125b9f6d [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>
Yingdi Yu61ec2722014-01-20 14:22:32 -08009#include <ndn-cpp-dev/common.hpp>
Jeff Thompsona8d7b062013-08-08 15:56:35 -070010
Yingdi Yu31b4af22014-01-14 14:13:00 -080011#if NDN_CPP_HAVE_TIME_H
12#include <time.h>
13#endif
14#if NDN_CPP_HAVE_SYS_TIME_H
15#include <sys/time.h>
16#endif
17
Jeff Thompsona8d7b062013-08-08 15:56:35 -070018using namespace std;
19
20namespace ndn {
21
Jeff Thompson0050abe2013-09-17 12:50:25 -070022string
Jeff Thompson10ad12a2013-09-24 16:19:11 -070023toHex(const vector<uint8_t>& array)
Jeff Thompsona8d7b062013-08-08 15:56:35 -070024{
Jeff Thompsonb0948a52013-09-12 14:38:26 -070025 if (!&array)
26 return "";
27
Jeff Thompsona8d7b062013-08-08 15:56:35 -070028 ostringstream result;
29 result.flags(ios::hex | ios::uppercase);
Jeff Thompson97223af2013-09-24 17:01:27 -070030 for (size_t i = 0; i < array.size(); ++i) {
Jeff Thompson10ad12a2013-09-24 16:19:11 -070031 uint8_t x = array[i];
Jeff Thompsona8d7b062013-08-08 15:56:35 -070032 if (x < 16)
33 result << '0';
34 result << (unsigned int)x;
35 }
36
37 return result.str();
38}
39
Yingdi Yu31b4af22014-01-14 14:13:00 -080040MillisecondsSince1970
41getNow()
42{
43 struct timeval t;
44 // Note: configure.ac requires gettimeofday.
45 gettimeofday(&t, 0);
46 return t.tv_sec * 1000.0 + t.tv_usec / 1000.0;
47}
48
49
Jeff Thompsona8d7b062013-08-08 15:56:35 -070050}
51