File Coverage

xs/serialize.xsi
Criterion Covered Total %
statement 16 24 66.6
branch 16 50 32.0
condition n/a
subroutine n/a
pod n/a
total 32 74 43.2


line stmt bran cond sub pod time code
1             MODE: INLINE
2             #include
3              
4             static inline size_t date_freeze_len (const Date& date) {
5             if (date.timezone()->is_local) return sizeof(ptime_t);
6             return sizeof(ptime_t) + date.timezone()->name.length();
7             }
8              
9             static inline void date_freeze (const Date& date, char* buf) {
10             if (sizeof(ptime_t) == 8) *((ptime_t*)buf) = panda::h2be64(date.epoch());
11             else *((ptime_t*)buf) = panda::h2be32(date.epoch());
12             buf += sizeof(ptime_t);
13              
14             if (date.timezone()->is_local) *buf = 0;
15             else {
16             auto len = date.timezone()->name.length();
17             std::memcpy(buf, date.timezone()->name.data(), len);
18             buf[len] = 0;
19             }
20             }
21              
22             static inline const char* date_thaw (ptime_t* epoch, const Timezone** zone, const char* ptr, size_t len) {
23             if (len < sizeof(ptime_t)) throw "Date: cannot 'thaw' - corrupted data";
24             if (sizeof(ptime_t) == 8) *epoch = panda::be2h64(*((ptime_t*)ptr));
25             else *epoch = panda::be2h32(*((ptime_t*)ptr));
26             ptr += sizeof(ptime_t);
27             if (*ptr == 0) {
28             *zone = NULL;
29             return ptr;
30             }
31             size_t znlen = strlen(ptr);
32             if (znlen) *zone = tzget(ptr);
33             return ptr + znlen;
34             }
35              
36             MODULE = Date PACKAGE = Date
37             PROTOTYPES: DISABLE
38              
39             Date* Date::HOOK_CLONE () {
40 0           RETVAL = new Date(*THIS);
41 0 0         PROTO = Object(ST(0)).stash();
    0          
42 0 0         }
    0          
43              
44             SV* Date::STORABLE_freeze (bool) {
45 5 50         size_t len = date_freeze_len(*THIS);
46 5 50         RETVAL = newSV(len);
47 5           SvPOK_on(RETVAL);
48 5           char* buf = SvPVX(RETVAL);
49 5 50         date_freeze(*THIS, buf);
50 5           SvCUR_set(RETVAL, len);
51             }
52              
53             Date* STORABLE_attach (SV* CLASS, bool, SV* serialized) {
54 10           STRLEN len;
55             const char* str = SvPV(serialized, len);
56 5 50         ptime_t epoch;
    0          
57             const Timezone* zone = nullptr;
58 5           date_thaw(&epoch, &zone, str, len);
59 5 50         RETVAL = new Date(epoch, zone);
60 5 50         PROTO = CLASS;
    50          
61 5 50         }
62              
63             ptime_t Date::TO_JSON () {
64 0           RETVAL = THIS->epoch();
65 0 0         }
66              
67             MODULE = Date PACKAGE = Date::Rel
68             PROTOTYPES: DISABLE
69              
70             DateRel* DateRel::HOOK_CLONE () {
71 0           RETVAL = new DateRel(*THIS);
72 0 0         PROTO = Object(ST(0)).stash();
    0          
73 0 0         }
    0          
74              
75             string DateRel::STORABLE_freeze (bool) {
76 4 100         RETVAL = THIS->from() ? THIS->to_string(DateRel::Format::iso8601i) : THIS->to_string();
    50          
    50          
    50          
77             }
78              
79             DateRel* STORABLE_attach (SV* CLASS, bool, string_view serialized) {
80 8           RETVAL = new DateRel(serialized);
81 4 50         PROTO = CLASS;
    50          
82 4 50         }