xs/serialize.xsi

filter: Statementstmt 66.6% 16 / 24 Branchbran 22.2% 12 / 54 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 35.9% 28 / 78 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/Timezone.xsi ↑ Summary xs/private.h »
1 MODE: INLINE
2 #include <cstring>
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 ▶ PROTO = Object(ST(0)).stash();
Branch: 3 branches
BranchTrueFalseTotal
PROTO = Object(ST(0)).stash(); 0 0 0
PROTO = Object(ST(0)).stash(); 0 0 0
PROTO = Object(ST(0)).stash(); 0 0 0
42 0 ▶}
Branch: 3 branches
BranchTrueFalseTotal
} 0 0 0
} 0 0 0
} 0 0 0
43  
44 SV* Date::STORABLE_freeze (bool) {
45 5 size_t len = date_freeze_len(*THIS);
46 5 RETVAL = newSV(len);
47 5 SvPOK_on(RETVAL);
48 5 char* buf = SvPVX(RETVAL);
49 5 date_freeze(*THIS, buf);
50 5 SvCUR_set(RETVAL, len);
51 }
52  
53 Date* STORABLE_attach (SV* CLASS, bool, SV* serialized) {
54 5 STRLEN len;
55 const char* str = SvPV(serialized, len);
56 5 ptime_t epoch;
57 const Timezone* zone = nullptr;
58 5 date_thaw(&epoch, &zone, str, len);
59 5 ▶ RETVAL = new Date(epoch, zone);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = new Date(epoch, zone); 5 0 5
60 5 ▶ PROTO = CLASS;
Branch: 3 branches
BranchTrueFalseTotal
PROTO = CLASS; 5 0 5
PROTO = CLASS; 5 0 5
PROTO = CLASS; 0 0 0
61 5 ▶}
Branch: 1 branch
BranchTrueFalseTotal
} 5 0 5
62  
63 ptime_t Date::TO_JSON () {
64 0 RETVAL = THIS->epoch();
65 0 ▶}
Branch: 2 branches
BranchTrueFalseTotal
} 0 0 0
} 0 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 ▶ PROTO = Object(ST(0)).stash();
Branch: 3 branches
BranchTrueFalseTotal
PROTO = Object(ST(0)).stash(); 0 0 0
PROTO = Object(ST(0)).stash(); 0 0 0
PROTO = Object(ST(0)).stash(); 0 0 0
73 0 ▶}
Branch: 3 branches
BranchTrueFalseTotal
} 0 0 0
} 0 0 0
} 0 0 0
74  
75 string DateRel::STORABLE_freeze (bool) {
76 4 ▶ RETVAL = THIS->from() ? THIS->to_string(DateRel::Format::iso8601i) : THIS->to_string();
Branch: 4 branches
BranchTrueFalseTotal
RETVAL = THIS->from() ? THIS->to_string(DateRel::Format::iso8601i) : THIS->to_string(); 1 3 4
RETVAL = THIS->from() ? THIS->to_string(DateRel::Format::iso8601i) : THIS->to_string(); 1 0 1
RETVAL = THIS->from() ? THIS->to_string(DateRel::Format::iso8601i) : THIS->to_string(); 3 0 3
RETVAL = THIS->from() ? THIS->to_string(DateRel::Format::iso8601i) : THIS->to_string(); 4 0 4
77 }
78  
79 DateRel* STORABLE_attach (SV* CLASS, bool, string_view serialized) {
80 4 RETVAL = new DateRel(serialized);
81 4 ▶ PROTO = CLASS;
Branch: 3 branches
BranchTrueFalseTotal
PROTO = CLASS; 4 0 4
PROTO = CLASS; 4 0 4
PROTO = CLASS; 0 0 0
82 4 ▶}
Branch: 1 branch
BranchTrueFalseTotal
} 4 0 4
« xs/Timezone.xsi ↑ Summary xs/private.h »