77 uint16_t time_hi_and_version;
86 time_hi_and_version(0),
89 node[0]= node[1]= node[2]= node[3]= node[4]= node[5]= 0;
92 void unpack(
const unsigned char *in)
94 const uint8_t *ptr=
reinterpret_cast<const uint8_t *
>(in);
98 tmp= (tmp << 8) | *ptr++;
99 tmp= (tmp << 8) | *ptr++;
100 tmp= (tmp << 8) | *ptr++;
104 tmp= (tmp << 8) | *ptr++;
108 tmp= (tmp << 8) | *ptr++;
109 time_hi_and_version = tmp;
112 tmp= (tmp << 8) | *ptr++;
115 memcpy(node, ptr, 6);
118 void pack(
unsigned char *out)
123 out[3] = (
unsigned char) tmp;
125 out[2] = (
unsigned char) tmp;
127 out[1] = (
unsigned char) tmp;
129 out[0] = (
unsigned char) tmp;
132 out[5] = (
unsigned char) tmp;
134 out[4] = (
unsigned char) tmp;
136 tmp = time_hi_and_version;
137 out[7] = (
unsigned char) tmp;
139 out[6] = (
unsigned char) tmp;
142 out[9] = (
unsigned char) tmp;
144 out[8] = (
unsigned char) tmp;
146 memcpy(out+10, node, 6);
149 bool parse(
const char *in)
155 for (i= 0, cp= in; i < DISPLAY_LENGTH; i++, cp++)
157 if ((i == 8) || (i == 13) || (i == 18) || (i == 23))
169 if (not isxdigit(*cp))
173 time_low= strtoul(in, NULL, 16);
174 time_mid= strtoul(in+9, NULL, 16);
175 time_hi_and_version= strtoul(in+14, NULL, 16);
176 clock_seq= strtoul(in+19, NULL, 16);
180 for (i= 0; i < 6; i++)
184 node[i]= strtoul(buf, NULL, 16);
190 void unparse(
char *out)
const
192 snprintf(out, DISPLAY_BUFFER_LENGTH,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
206 void time(timeval& ret_val)
const
211 high= time_mid | ((time_hi_and_version & 0xFFF) << 16);
212 clock_reg= time_low | ((uint64_t) high << 32);
214 clock_reg -= (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
215 ret_val.tv_sec = clock_reg / 10000000;
216 ret_val.tv_usec = (clock_reg % 10000000) / 10;
218 bool isTimeType()
const
220 return ((time_hi_and_version >> 12) & 0xF) == 1;
223 static const size_t LENGTH= 16;
224 static const size_t DISPLAY_LENGTH= 36;
225 static const size_t DISPLAY_BUFFER_LENGTH= DISPLAY_LENGTH+1;