MessagePack for C
msgpack
timestamp.h
Go to the documentation of this file.
1
/*
2
* MessagePack for C TimeStamp
3
*
4
* Copyright (C) 2018 KONDO Takatoshi
5
*
6
* Distributed under the Boost Software License, Version 1.0.
7
* (See accompanying file LICENSE_1_0.txt or copy at
8
* http://www.boost.org/LICENSE_1_0.txt)
9
*/
10
#ifndef MSGPACK_TIMESTAMP_H
11
#define MSGPACK_TIMESTAMP_H
12
13
#include <
msgpack/object.h
>
14
15
#ifdef __cplusplus
16
extern
"C"
{
17
#endif
18
19
20
typedef
struct
msgpack_timestamp
{
21
int64_t
tv_sec
;
22
uint32_t
tv_nsec
;
23
}
msgpack_timestamp
;
24
25
static
inline
bool
msgpack_object_to_timestamp(
const
msgpack_object
*
obj
,
msgpack_timestamp
* ts) {
26
if
(
obj
->type !=
MSGPACK_OBJECT_EXT
)
return
false
;
27
if
(
obj
->via.ext.type != -1)
return
false
;
28
switch
(
obj
->via.ext.size) {
29
case
4:
30
ts->
tv_nsec
= 0;
31
{
32
uint32_t v;
33
_msgpack_load32
(uint32_t,
obj
->via.ext.ptr, &v);
34
ts->
tv_sec
= v;
35
}
36
return
true
;
37
case
8: {
38
uint64_t value;
39
_msgpack_load64
(uint64_t,
obj
->via.ext.ptr, &value);
40
ts->
tv_nsec
= (uint32_t)(value >> 34);
41
ts->
tv_sec
= value & 0x00000003ffffffffLL;
42
return
true
;
43
}
44
case
12:
45
_msgpack_load32
(uint32_t,
obj
->via.ext.ptr, &ts->
tv_nsec
);
46
_msgpack_load64
(int64_t,
obj
->via.ext.ptr + 4, &ts->
tv_sec
);
47
return
true
;
48
default
:
49
return
false
;
50
}
51
}
52
53
54
#ifdef __cplusplus
55
}
56
#endif
57
58
#endif
/* msgpack/timestamp.h */
MSGPACK_OBJECT_EXT
@ MSGPACK_OBJECT_EXT
Definition:
object.h:42
_msgpack_load32
#define _msgpack_load32(cast, from, to)
Definition:
sysdep.h:165
msgpack_timestamp::tv_nsec
uint32_t tv_nsec
Definition:
timestamp.h:22
msgpack_object
Definition:
object.h:90
_msgpack_load64
#define _msgpack_load64(cast, from, to)
Definition:
sysdep.h:169
msgpack_timestamp
struct msgpack_timestamp msgpack_timestamp
obj
msgpack_unpack_object obj
Definition:
unpack_template.h:111
msgpack_timestamp
Definition:
timestamp.h:20
msgpack_timestamp::tv_sec
int64_t tv_sec
Definition:
timestamp.h:21
object.h
Generated by
1.8.17