GCC Code Coverage Report


Directory: src/gate/
File: src/gate/values.c
Date: 2026-02-03 22:06:38
Exec Total Coverage
Lines: 821 902 91.0%
Functions: 36 38 94.7%
Branches: 421 630 66.8%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/values.h"
30 #include "gate/memalloc.h"
31 #include "gate/results.h"
32 #include "gate/mathematics.h"
33 #include "gate/serializers.h"
34
35
36 189 gate_value_t* gate_value_create(gate_type_id_t value_type, void const* src, gate_value_t* dst)
37 {
38 189 gate_value_t* ret = NULL;
39 189 gate_size_t len = gate_type_length(value_type);
40 189 gate_array_t const* const ptr_array = (gate_array_t const*)src;
41 189 gate_string_t const* const ptr_string = (gate_string_t const*)src;
42 189 gate_blob_t const* const ptr_blob = (gate_blob_t const*)src;
43
44
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 179 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 179 times.
189 if ((len != 0) && (dst != NULL))
45 {
46 /* plain copy of bits */
47
1/2
✓ Branch 0 taken 179 times.
✗ Branch 1 not taken.
179 if (len > 0)
48 {
49 179 gate_mem_copy(&dst->content, src, len);
50 }
51 179 dst->value_type = value_type;
52 179 ret = dst;
53
4/5
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 150 times.
179 switch (value_type)
54 {
55 4 case GATE_TYPE_ARRAY:
56 {
57
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (gate_array_duplicate(&dst->content.array_value, ptr_array) == NULL)
58 {
59 ret = NULL;
60 }
61 4 break;
62 }
63 5 case GATE_TYPE_BLOB:
64 {
65
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
5 if (gate_blob_create_duplicate(&dst->content.blob_value, ptr_blob) == NULL)
66 {
67 ret = NULL;
68 }
69 5 break;
70 }
71 20 case GATE_TYPE_STRING:
72 {
73
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (gate_string_clone(&dst->content.string_value, ptr_string) == NULL)
74 {
75 ret = NULL;
76 }
77 20 break;
78 }
79 case GATE_TYPE_OBJECT:
80 {
81 if (dst->content.object_value != NULL)
82 {
83 gate_object_retain(dst->content.object_value);
84 }
85 break;
86 }
87 }
88 10 }
89 189 return ret;
90 }
91 53 gate_value_t* gate_value_clone(gate_value_t const* src, gate_value_t* dst)
92 {
93 53 gate_value_t* ret = NULL;
94
2/4
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53 times.
✗ Branch 3 not taken.
53 if ((src != NULL) && (dst != NULL))
95 {
96 53 ret = gate_value_create(src->value_type, &src->content.address_value, dst);
97 }
98 53 return ret;
99 }
100 553 void gate_value_release(gate_value_t* dst)
101 {
102
1/2
✓ Branch 0 taken 553 times.
✗ Branch 1 not taken.
553 if (dst != NULL)
103 {
104
4/5
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 498 times.
553 switch (dst->value_type)
105 {
106 4 case GATE_TYPE_ARRAY:
107 {
108 4 gate_array_release(&dst->content.array_value);
109 4 break;
110 }
111 33 case GATE_TYPE_STRING:
112 {
113 33 gate_string_release(&dst->content.string_value);
114 33 break;
115 }
116 18 case GATE_TYPE_BLOB:
117 {
118 18 gate_blob_release(&dst->content.blob_value);
119 18 break;
120 }
121 case GATE_TYPE_OBJECT:
122 {
123 if (dst->content.object_value != NULL)
124 {
125 gate_object_release(dst->content.object_value);
126 }
127 break;
128 }
129 498 default:
130 {
131 498 break;
132 }
133 }
134 553 gate_mem_clear(dst, sizeof(gate_value_t));
135 553 dst->value_type = GATE_TYPE_EMPTY;
136 }
137 553 }
138
139 24 gate_result_t gate_value_get(gate_value_t const* src, void* ptrdst, gate_size_t dstlen)
140 {
141 24 gate_result_t ret = GATE_RESULT_FAILED;
142
3/6
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
24 if ((src == NULL) || (ptrdst == NULL) || (dstlen == 0))
143 {
144 ret = GATE_RESULT_INVALIDARG;
145 }
146
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 else if (gate_type_length(src->value_type) != dstlen)
147 {
148 ret = GATE_RESULT_INCORRECTTYPE;
149 }
150 else
151 {
152
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (gate_mem_copy(ptrdst, &src->content.ptr_value, dstlen) == NULL)
153 {
154 ret = GATE_RESULT_FAILED;
155 }
156 else
157 {
158 24 ret = GATE_RESULT_OK;
159 }
160 }
161 24 return ret;
162 }
163
164 46 void const* gate_value_get_ptr(gate_value_t const* src)
165 {
166
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 return src ? &src->content.ptr_value : NULL;
167 }
168
169 69 gate_type_id_t gate_value_type(gate_value_t const* src)
170 {
171
1/2
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
69 return src ? src->value_type : GATE_TYPE_EMPTY;
172 }
173
174
175
176
177
178 250 gate_result_t gate_value_load_int64(gate_type_id_t value_type, void const* src, gate_int64_t* dst)
179 {
180 250 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
181 250 gate_time_t tm = GATE_TIME_INIT;
182 gate_result_t res;
183
184
24/24
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 12 times.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 21 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 10 times.
✓ Branch 12 taken 9 times.
✓ Branch 13 taken 10 times.
✓ Branch 14 taken 9 times.
✓ Branch 15 taken 9 times.
✓ Branch 16 taken 13 times.
✓ Branch 17 taken 9 times.
✓ Branch 18 taken 9 times.
✓ Branch 19 taken 9 times.
✓ Branch 20 taken 9 times.
✓ Branch 21 taken 9 times.
✓ Branch 22 taken 10 times.
✓ Branch 23 taken 2 times.
250 switch (value_type)
185 {
186 12 case GATE_TYPE_BOOL: *dst = (*(gate_bool_t const*)src) ? 1 : 0; return GATE_RESULT_OK;
187 12 case GATE_TYPE_I8: *dst = (gate_int64_t)(*(gate_int8_t const*)src); return GATE_RESULT_OK;
188 10 case GATE_TYPE_UI8: *dst = (gate_int64_t)(*(gate_uint8_t const*)src); return GATE_RESULT_OK;
189 12 case GATE_TYPE_I16: *dst = (gate_int64_t)(*(gate_int16_t const*)src); return GATE_RESULT_OK;
190 12 case GATE_TYPE_UI16: *dst = (gate_int64_t)(*(gate_uint16_t const*)src); return GATE_RESULT_OK;
191 12 case GATE_TYPE_I32: *dst = (gate_int64_t)(*(gate_int32_t const*)src); return GATE_RESULT_OK;
192 12 case GATE_TYPE_UI32: *dst = (gate_int64_t)(*(gate_uint32_t const*)src); return GATE_RESULT_OK;
193 21 case GATE_TYPE_I64: *dst = (gate_int64_t)(*(gate_int64_t const*)src); return GATE_RESULT_OK;
194 12 case GATE_TYPE_UI64: *dst = (gate_int64_t)(*(gate_uint64_t const*)src); return GATE_RESULT_OK;
195 9 case GATE_TYPE_R32: *dst = (gate_int64_t)(*(gate_real32_t const*)src); return GATE_RESULT_OK;
196 9 case GATE_TYPE_R64: *dst = (gate_int64_t)(*(gate_real64_t const*)src); return GATE_RESULT_OK;
197 10 case GATE_TYPE_ADDRESS: *dst = (gate_uintptr_t)(*(gate_uint64_t const*)src); return GATE_RESULT_OK;
198
199 9 case GATE_TYPE_DATAPTR: *dst = (gate_int64_t)(gate_intptr_t) * ((void* const*)src); return GATE_RESULT_OK;
200 10 case GATE_TYPE_FUNCPTR: *dst = (gate_intptr_t)(void*)(gate_funcptr_t) * (gate_funcptr_t const*)src; return GATE_RESULT_OK;
201 9 case GATE_TYPE_CSTR:
202 {
203 9 char const* const text = *((char const* const*)src);
204 9 return gate_str_parse_int64(text, gate_str_length(text), dst) > 0
205 ? GATE_RESULT_OK
206
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 : GATE_RESULT_FAILED;
207 }
208 9 case GATE_TYPE_WSTR:
209 {
210 9 wchar_t const* const text = *((wchar_t const* const*)src);
211 9 char buffer[64] = GATE_INIT_EMPTY;
212 9 gate_size_t used = gate_str_print_wtext(buffer, sizeof(buffer), text, gate_wstr_length(text));
213 9 return gate_str_parse_int64(buffer, used, dst) > 0
214 ? GATE_RESULT_OK
215
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 : GATE_RESULT_FAILED;
216 }
217 13 case GATE_TYPE_STRING:
218 {
219 13 return gate_str_parse_int64(((gate_string_t const*)src)->str, ((gate_string_t const*)src)->length, dst) > 0
220 ? GATE_RESULT_OK
221
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 : GATE_RESULT_FAILED;
222 }
223 9 case GATE_TYPE_DATE:
224 {
225 9 dt.date = *((gate_date_t const*)src);
226 9 res = gate_date_to_time(&dt, &tm);
227
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (GATE_SUCCEEDED(res))
228 {
229 9 res = gate_time_to_unix(tm.timestamp, dst);
230 }
231 9 return res;
232 }
233 9 case GATE_TYPE_DAYTIME:
234 {
235 9 dt.date.year = 1601;
236 9 dt.date.month = 1;
237 9 dt.date.day = 1;
238 9 dt.time = *((gate_daytime_t const*)src);
239 9 res = gate_date_to_time(&dt, &tm);
240
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (GATE_SUCCEEDED(res))
241 {
242 9 *dst = (gate_int64_t)tm.timestamp;
243 }
244 9 return res;
245 }
246 9 case GATE_TYPE_DATETIME:
247 {
248 9 dt = *((gate_datetime_t const*)src);
249 9 res = gate_date_to_time(&dt, &tm);
250
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (GATE_SUCCEEDED(res))
251 {
252 9 res = gate_time_to_unix(tm.timestamp, dst);
253 }
254 9 return res;
255 }
256 9 case GATE_TYPE_TIME:
257 {
258 9 tm = *((gate_time_t const*)src);
259 9 res = gate_time_to_unix(tm.timestamp, dst);
260 9 return res;
261 }
262 9 case GATE_TYPE_GUID:
263 {
264 9 gate_guid_t const* g = (gate_guid_t const*)src;
265 18 gate_uint64_t a = (((gate_uint64_t)g->item1) << 32)
266 9 | (((gate_uint64_t)g->item2) << 16)
267 9 | (((gate_uint64_t)g->item3));
268 18 gate_uint64_t b = (((gate_uint64_t)g->item4[0]) << 56)
269 9 | (((gate_uint64_t)g->item4[1]) << 48)
270 9 | (((gate_uint64_t)g->item4[2]) << 40)
271 9 | (((gate_uint64_t)g->item4[3]) << 32)
272 9 | (((gate_uint64_t)g->item4[4]) << 24)
273 9 | (((gate_uint64_t)g->item4[5]) << 16)
274 9 | (((gate_uint64_t)g->item4[6]) << 8)
275 9 | (((gate_uint64_t)g->item4[7]));
276 9 *dst = (gate_int64_t)(a | b);
277 9 return GATE_RESULT_OK;
278 }
279 10 case GATE_TYPE_BLOB:
280 {
281 10 gate_blob_t const* b = (gate_blob_t const*)src;
282 10 *dst = (gate_int64_t)gate_blob_length(b);
283 10 return GATE_RESULT_OK;
284 }
285 }
286 2 return GATE_RESULT_NOTSUPPORTED;
287 }
288 9 gate_result_t gate_value_load_real64(gate_type_id_t value_type, void const* src, gate_real64_t* dst)
289 {
290 gate_int64_t tmp;
291 gate_result_t res;
292
3/5
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
9 switch (value_type)
293 {
294 3 case GATE_TYPE_R32: *dst = (gate_real64_t) * ((gate_real32_t const*)src); return GATE_RESULT_OK;
295 5 case GATE_TYPE_R64: *dst = (gate_real64_t) * ((gate_real64_t const*)src); return GATE_RESULT_OK;
296 case GATE_TYPE_CSTR:
297 {
298 return gate_str_parse_real(*((char const* const*)src), gate_str_length(*((char const* const*)src)), dst) > 0
299 ? GATE_RESULT_OK
300 : GATE_RESULT_FAILED;
301 }
302 1 case GATE_TYPE_STRING:
303 {
304 1 return gate_str_parse_real(((gate_string_t const*)src)->str, ((gate_string_t const*)src)->length, dst) > 0
305 ? GATE_RESULT_OK
306
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 : GATE_RESULT_FAILED;
307 }
308 default:
309 {
310 res = gate_value_load_int64(value_type, src, &tmp);
311 if (GATE_SUCCEEDED(res))
312 {
313 *dst = (gate_real64_t)tmp;
314 }
315 return res;
316 }
317 }
318 }
319
320
321
322 25 gate_result_t gate_value_load_bool(gate_type_id_t value_type, void const* src, gate_bool_t* dst)
323 {
324 gate_result_t ret;
325 gate_int64_t tmp;
326 25 ret = gate_value_load_int64(value_type, src, &tmp);
327
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (GATE_SUCCEEDED(ret)) *dst = (tmp != 0);
328 25 return ret;
329 }
330 24 gate_result_t gate_value_load_int8(gate_type_id_t value_type, void const* src, gate_int8_t* dst)
331 {
332 gate_result_t ret;
333 gate_int64_t tmp;
334 24 ret = gate_value_load_int64(value_type, src, &tmp);
335
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (GATE_SUCCEEDED(ret)) *dst = (gate_int8_t)tmp;
336 24 return ret;
337 }
338 24 gate_result_t gate_value_load_int16(gate_type_id_t value_type, void const* src, gate_int16_t* dst)
339 {
340 gate_result_t ret;
341 gate_int64_t tmp;
342 24 ret = gate_value_load_int64(value_type, src, &tmp);
343
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (GATE_SUCCEEDED(ret)) *dst = (gate_int16_t)tmp;
344 24 return ret;
345 }
346 26 gate_result_t gate_value_load_int32(gate_type_id_t value_type, void const* src, gate_int32_t* dst)
347 {
348 gate_result_t ret;
349 gate_int64_t tmp;
350 26 ret = gate_value_load_int64(value_type, src, &tmp);
351
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if (GATE_SUCCEEDED(ret)) *dst = (gate_int32_t)tmp;
352 26 return ret;
353 }
354 23 gate_result_t gate_value_load_uint8(gate_type_id_t value_type, void const* src, gate_uint8_t* dst)
355 {
356 gate_result_t ret;
357 gate_int64_t tmp;
358 23 ret = gate_value_load_int64(value_type, src, &tmp);
359
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 if (GATE_SUCCEEDED(ret)) *dst = (gate_uint8_t)tmp;
360 23 return ret;
361 }
362 24 gate_result_t gate_value_load_uint16(gate_type_id_t value_type, void const* src, gate_uint16_t* dst)
363 {
364 gate_result_t ret;
365 gate_int64_t tmp;
366 24 ret = gate_value_load_int64(value_type, src, &tmp);
367
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (GATE_SUCCEEDED(ret)) *dst = (gate_uint16_t)tmp;
368 24 return ret;
369 }
370 24 gate_result_t gate_value_load_uint32(gate_type_id_t value_type, void const* src, gate_uint32_t* dst)
371 {
372 gate_result_t ret;
373 gate_int64_t tmp;
374 24 ret = gate_value_load_int64(value_type, src, &tmp);
375
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (GATE_SUCCEEDED(ret)) *dst = (gate_uint32_t)tmp;
376 24 return ret;
377 }
378 24 gate_result_t gate_value_load_uint64(gate_type_id_t value_type, void const* src, gate_uint64_t* dst)
379 {
380 gate_result_t ret;
381 gate_int64_t tmp;
382 24 ret = gate_value_load_int64(value_type, src, &tmp);
383
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (GATE_SUCCEEDED(ret)) *dst = (gate_uint64_t)tmp;
384 24 return ret;
385 }
386
387
388 1 gate_result_t gate_value_load_real32(gate_type_id_t value_type, void const* src, gate_real32_t* dst)
389 {
390 gate_result_t ret;
391 gate_real64_t tmp;
392 1 ret = gate_value_load_real64(value_type, src, &tmp);
393
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (GATE_SUCCEEDED(ret)) *dst = (gate_real32_t)tmp;
394 1 return ret;
395 }
396
397 53 gate_result_t gate_value_load_string(gate_type_id_t value_type, void const* src, gate_string_t* dst)
398 {
399 gate_result_t ret;
400 gate_int64_t tmpint;
401 gate_real64_t tmpreal;
402 gate_strbuilder_t builder;
403
404
10/10
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 31 times.
53 switch (value_type)
405 {
406 6 case GATE_TYPE_R32:
407 case GATE_TYPE_R64:
408 {
409 6 ret = gate_value_load_real64(value_type, src, &tmpreal);
410
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (GATE_SUCCEEDED(ret))
411 {
412 6 gate_strbuilder_create(&builder, 32);
413 6 gate_strbuilder_append_real(&builder, tmpreal, 0, 6, 0);
414 6 gate_strbuilder_to_string(&builder, dst);
415 6 gate_strbuilder_release(&builder);
416 }
417 6 return ret;
418 }
419 2 case GATE_TYPE_DATAPTR:
420 case GATE_TYPE_CSTR:
421 {
422 2 return (NULL == gate_string_create(dst, *((char const* const*)src), gate_str_length(*((char const* const*)src))))
423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
424 }
425 1 case GATE_TYPE_WSTR:
426 {
427 gate_string_t* r;
428 if (sizeof(wchar_t) == sizeof(gate_char16_t))
429 {
430 gate_char16_t const* const text = *((gate_char16_t const* const*)src);
431 r = gate_string_create_utf16(dst, text, gate_str16_length(text));
432 }
433 else
434 {
435 1 gate_char32_t const* const text = *((gate_char32_t const* const*)src);
436 1 r = gate_string_create_utf32(dst, text, gate_str32_length(text));
437 }
438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 return (r == NULL) ? GATE_RESULT_FAILED : GATE_RESULT_OK;
439 }
440 8 case GATE_TYPE_STRING:
441 {
442 8 return (NULL == gate_string_duplicate(dst, (gate_string_t const*)src))
443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
444 }
445 1 case GATE_TYPE_GUID:
446 {
447 1 gate_guid_t const* g = (gate_guid_t const*)src;
448 char buffer[40];
449 1 gate_result_t result = gate_guid_to_string(g, buffer);
450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
451 1 return (NULL == gate_string_create(dst, buffer, gate_str_length_max(buffer, sizeof(buffer))))
452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
453 }
454 1 case GATE_TYPE_DATE:
455 {
456 char buffer[128];
457 1 gate_size_t len = sizeof(buffer);
458 gate_datetime_t dt;
459 gate_result_t result;
460 1 gate_mem_copy(&dt.date, src, sizeof(gate_date_t));
461 1 gate_mem_clear(&dt.time, sizeof(gate_daytime_t));
462 1 result = gate_date_to_string(&dt, 0, "{YYYY}-{MM}-{DD}", buffer, &len);
463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
464 1 return (NULL == gate_string_create(dst, buffer, len))
465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
466 }
467 1 case GATE_TYPE_DAYTIME:
468 {
469 char buffer[128];
470 1 gate_size_t len = sizeof(buffer);
471 gate_datetime_t dt;
472 gate_result_t result;
473 1 gate_mem_clear(&dt.date, sizeof(gate_date_t));
474 1 gate_mem_copy(&dt.time, src, sizeof(gate_daytime_t));
475 1 result = gate_date_to_string(&dt, 0, "{hh}:{mm}:{ss}.{SSS}", buffer, &len);
476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
477 1 return (NULL == gate_string_create(dst, buffer, len))
478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
479 }
480 1 case GATE_TYPE_DATETIME:
481 {
482 1 gate_datetime_t const* dt = (gate_datetime_t const*)src;
483 char buffer[128];
484 1 gate_size_t len = sizeof(buffer);
485 1 gate_result_t result = gate_date_to_string(dt, 0, NULL, buffer, &len);
486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
487 1 return (NULL == gate_string_create(dst, buffer, len))
488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
489 }
490 1 case GATE_TYPE_TIME:
491 {
492 1 gate_time_t const* t = (gate_time_t const*)src;
493 char buffer[128];
494 1 gate_size_t len = sizeof(buffer);
495 1 gate_result_t result = gate_time_to_string(t, NULL, buffer, &len);
496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
497 1 return (NULL == gate_string_create(dst, buffer, len))
498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
499 }
500 31 default:
501 {
502 31 ret = gate_value_load_int64(value_type, src, &tmpint);
503
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 2 times.
31 if (GATE_SUCCEEDED(ret))
504 {
505 29 gate_strbuilder_create(&builder, 16);
506 29 gate_strbuilder_append_int64(&builder, tmpint);
507 29 gate_strbuilder_to_string(&builder, dst);
508 29 gate_strbuilder_release(&builder);
509 }
510 31 return ret;
511 }
512 }
513 }
514
515 23 gate_result_t gate_value_load_blob(gate_type_id_t value_type, void const* src, gate_blob_t* dst)
516 {
517 static gate_blob_t const true_blob = GATE_BLOB_INIT_STATIC("true");
518 23 gate_blob_t* ptr_loaded = NULL;
519
520
2/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
23 if (!src || !dst)
521 {
522 return GATE_RESULT_NULLPOINTER;
523 }
524
525
23/24
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
23 switch (value_type)
526 {
527 1 case GATE_TYPE_BOOL: ptr_loaded = gate_blob_create_duplicate(dst, &true_blob); break;
528 1 case GATE_TYPE_I8: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_int8_t)); break;
529 1 case GATE_TYPE_I16: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_int16_t)); break;
530 1 case GATE_TYPE_I32: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_int32_t)); break;
531 1 case GATE_TYPE_I64: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_int64_t)); break;
532 1 case GATE_TYPE_UI8: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uint8_t)); break;
533 1 case GATE_TYPE_UI16: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uint16_t)); break;
534 1 case GATE_TYPE_UI32: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uint32_t)); break;
535 1 case GATE_TYPE_UI64: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uint64_t)); break;
536 1 case GATE_TYPE_R32: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_real32_t)); break;
537 1 case GATE_TYPE_R64: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_real64_t)); break;
538 1 case GATE_TYPE_ADDRESS: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uintptr_t)); break;
539 1 case GATE_TYPE_DATAPTR: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_dataptr_t)); break;
540 1 case GATE_TYPE_FUNCPTR: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_funcptr_t)); break;
541 1 case GATE_TYPE_CSTR: ptr_loaded = gate_blob_create(dst, *((char const* const*)src), gate_str_length(*((char const* const*)src))); break;
542 1 case GATE_TYPE_WSTR: ptr_loaded = gate_blob_create(dst, *((wchar_t const* const*)src), sizeof(wchar_t) * gate_wstr_length(*((wchar_t const* const*)src))); break;
543 1 case GATE_TYPE_GUID: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_guid_t)); break;
544 1 case GATE_TYPE_DATE: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_date_t)); break;
545 1 case GATE_TYPE_DAYTIME: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_daytime_t)); break;
546 1 case GATE_TYPE_DATETIME: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_datetime_t)); break;
547 1 case GATE_TYPE_TIME: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_time_t)); break;
548 1 case GATE_TYPE_STRING: ptr_loaded = gate_blob_create(dst, gate_string_ptr((gate_string_t const*)src, 0), gate_string_length((gate_string_t const*)src)); break;
549 1 case GATE_TYPE_BLOB: ptr_loaded = gate_blob_create_clone(dst, (gate_blob_t const*)src); break;
550 default: return GATE_RESULT_NOTSUPPORTED;
551 }
552
553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 return (ptr_loaded == NULL) ? GATE_RESULT_FAILED : GATE_RESULT_OK;
554 }
555
556
557
558
559 112 gate_result_t gate_value_save_int64(gate_int64_t src, gate_type_id_t dst_type, void* dst)
560 {
561
23/24
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 14 taken 6 times.
✓ Branch 15 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 17 taken 6 times.
✓ Branch 18 taken 6 times.
✓ Branch 19 taken 6 times.
✓ Branch 20 taken 6 times.
✓ Branch 21 taken 4 times.
✓ Branch 22 taken 6 times.
✗ Branch 23 not taken.
112 switch (dst_type)
562 {
563 4 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = (src == 0) ? true : false; break;
564 4 case GATE_TYPE_I8: *((gate_int8_t*)dst) = (gate_int8_t)src; break;
565 4 case GATE_TYPE_I16: *((gate_int16_t*)dst) = (gate_int16_t)src; break;
566 4 case GATE_TYPE_I32: *((gate_int32_t*)dst) = (gate_int32_t)src; break;
567 4 case GATE_TYPE_I64: *((gate_int64_t*)dst) = (gate_int64_t)src; break;
568 4 case GATE_TYPE_UI8: *((gate_uint8_t*)dst) = (gate_uint8_t)src; break;
569 4 case GATE_TYPE_UI16: *((gate_uint16_t*)dst) = (gate_uint16_t)src; break;
570 4 case GATE_TYPE_UI32: *((gate_uint32_t*)dst) = (gate_uint32_t)src; break;
571 4 case GATE_TYPE_UI64: *((gate_uint64_t*)dst) = (gate_uint64_t)src; break;
572 4 case GATE_TYPE_R32: *((gate_real32_t*)dst) = (gate_real32_t)src; break;
573 4 case GATE_TYPE_R64: *((gate_real64_t*)dst) = (gate_real64_t)src; break;
574 4 case GATE_TYPE_ADDRESS: *((gate_uintptr_t*)dst) = (gate_uintptr_t)src; break;
575 6 case GATE_TYPE_DATAPTR: *((gate_dataptr_t*)dst) = (gate_dataptr_t)(gate_intptr_t)src; break;
576 6 case GATE_TYPE_FUNCPTR: *((gate_funcptr_t*)dst) = (gate_funcptr_t)(gate_intptr_t)src; break;
577 6 case GATE_TYPE_CSTR: *((gate_cstr_t*)dst) = NULL; break;
578 6 case GATE_TYPE_WSTR: *((gate_wstr_t*)dst) = NULL; break;
579 6 case GATE_TYPE_GUID: gate_mem_copy(dst, &src, sizeof(src)); break;
580 6 case GATE_TYPE_DATE:
581 {
582 6 gate_time_t tm = GATE_TIME_INIT;
583 6 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
584 6 gate_time_from_unix(src, &tm.timestamp);
585 6 gate_time_to_datetime(&tm, &dt);
586 6 *((gate_date_t*)dst) = dt.date;
587 6 break;
588 }
589 6 case GATE_TYPE_DAYTIME:
590 {
591 6 const gate_uint64_t day_seconds = (gate_uint64_t)src;
592 gate_daytime_t tm;
593 6 gate_uint32_t hour_seconds = (gate_uint32_t)(day_seconds % 3600);
594 6 tm.hour = (gate_uint8_t)(day_seconds / 3600);
595 6 tm.minute = (gate_uint8_t)(hour_seconds / 60);
596 6 tm.second = (gate_uint8_t)(hour_seconds % 60);
597 6 tm.microsecond = 0;
598 6 *((gate_daytime_t*)dst) = tm;
599 6 break;
600 }
601 6 case GATE_TYPE_DATETIME:
602 {
603 6 gate_time_t tm = GATE_TIME_INIT;
604 6 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
605 6 gate_time_from_unix(src, &tm.timestamp);
606 6 gate_time_to_datetime(&tm, &dt);
607 6 *((gate_datetime_t*)dst) = dt;
608 6 break;
609 }
610 6 case GATE_TYPE_TIME:
611 {
612 6 gate_time_t tm = GATE_TIME_INIT;
613 6 gate_time_from_unix(src, &tm.timestamp);
614 6 *((gate_time_t*)dst) = tm;
615 6 break;
616 }
617 4 case GATE_TYPE_STRING:
618 {
619 char strbuffer[128];
620 4 gate_size_t strused = gate_str_print_int64(strbuffer, sizeof(strbuffer), src);
621
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (NULL == gate_string_create((gate_string_t*)dst, strbuffer, strused))
622 {
623 return GATE_RESULT_FAILED;
624 }
625 4 break;
626 }
627 6 case GATE_TYPE_BLOB:
628 {
629 char strbuffer[128];
630 6 gate_size_t strused = gate_str_print_int64(strbuffer, sizeof(strbuffer), src);
631
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (NULL == gate_blob_create((gate_blob_t*)dst, strbuffer, strused))
632 {
633 return GATE_RESULT_FAILED;
634 }
635 6 break;
636 }
637
638 default:
639 {
640 return GATE_RESULT_NOTSUPPORTED;
641 }
642 }
643 112 return GATE_RESULT_OK;
644 }
645 92 gate_result_t gate_value_save_uint64(gate_uint64_t src, gate_type_id_t dst_type, void* dst)
646 {
647
23/24
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 4 times.
✓ Branch 18 taken 4 times.
✓ Branch 19 taken 4 times.
✓ Branch 20 taken 4 times.
✓ Branch 21 taken 4 times.
✓ Branch 22 taken 4 times.
✗ Branch 23 not taken.
92 switch (dst_type)
648 {
649 4 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = (src == 0) ? true : false; break;
650 4 case GATE_TYPE_I8: *((gate_int8_t*)dst) = (gate_int8_t)src; break;
651 4 case GATE_TYPE_I16: *((gate_int16_t*)dst) = (gate_int16_t)src; break;
652 4 case GATE_TYPE_I32: *((gate_int32_t*)dst) = (gate_int32_t)src; break;
653 4 case GATE_TYPE_I64: *((gate_int64_t*)dst) = (gate_int64_t)src; break;
654 4 case GATE_TYPE_UI8: *((gate_uint8_t*)dst) = (gate_uint8_t)src; break;
655 4 case GATE_TYPE_UI16: *((gate_uint16_t*)dst) = (gate_uint16_t)src; break;
656 4 case GATE_TYPE_UI32: *((gate_uint32_t*)dst) = (gate_uint32_t)src; break;
657 4 case GATE_TYPE_UI64: *((gate_uint64_t*)dst) = (gate_uint64_t)src; break;
658 4 case GATE_TYPE_R32: *((gate_real32_t*)dst) = (gate_real32_t)(gate_int64_t)src; break;
659 4 case GATE_TYPE_R64: *((gate_real64_t*)dst) = (gate_real64_t)(gate_int64_t)src; break;
660 4 case GATE_TYPE_ADDRESS: *((gate_uintptr_t*)dst) = (gate_uintptr_t)src; break;
661 4 case GATE_TYPE_DATAPTR: *((gate_dataptr_t*)dst) = (gate_dataptr_t)(gate_uintptr_t)src; break;
662 4 case GATE_TYPE_FUNCPTR: *((gate_funcptr_t*)dst) = (gate_funcptr_t)(gate_uintptr_t)src; break;
663 4 case GATE_TYPE_CSTR: *((gate_cstr_t*)dst) = NULL; break;
664 4 case GATE_TYPE_WSTR: *((gate_wstr_t*)dst) = NULL; break;
665 4 case GATE_TYPE_GUID: gate_mem_copy(dst, &src, sizeof(src)); break;
666 4 case GATE_TYPE_DATE:
667 {
668 4 gate_time_t tm = GATE_TIME_INIT;
669 4 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
670 4 gate_time_from_unix((gate_int64_t)src, &tm.timestamp);
671 4 gate_time_to_datetime(&tm, &dt);
672 4 *((gate_date_t*)dst) = dt.date;
673 4 break;
674 }
675 4 case GATE_TYPE_DAYTIME:
676 {
677 4 const gate_uint64_t day_seconds = src;
678 gate_daytime_t tm;
679 4 gate_uint32_t hour_seconds = (gate_uint32_t)(day_seconds % 3600);
680 4 tm.hour = (gate_uint8_t)(day_seconds / 3600);
681 4 tm.minute = (gate_uint8_t)(hour_seconds / 60);
682 4 tm.second = (gate_uint8_t)(hour_seconds % 60);
683 4 tm.microsecond = 0;
684 4 *((gate_daytime_t*)dst) = tm;
685 4 break;
686 }
687 4 case GATE_TYPE_DATETIME:
688 {
689 4 gate_time_t tm = GATE_TIME_INIT;
690 4 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
691 4 gate_time_from_unix((gate_int64_t)src, &tm.timestamp);
692 4 gate_time_to_datetime(&tm, &dt);
693 4 *((gate_datetime_t*)dst) = dt;
694 4 break;
695 }
696 4 case GATE_TYPE_TIME:
697 {
698 4 gate_time_t tm = GATE_TIME_INIT;
699 4 gate_time_from_unix((gate_int64_t)src, &tm.timestamp);
700 4 *((gate_time_t*)dst) = tm;
701 4 break;
702 }
703 4 case GATE_TYPE_STRING:
704 {
705 char strbuffer[128];
706 4 gate_size_t strused = gate_str_print_uint64(strbuffer, sizeof(strbuffer), src);
707
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (NULL == gate_string_create((gate_string_t*)dst, strbuffer, strused))
708 {
709 return GATE_RESULT_FAILED;
710 }
711 4 break;
712 }
713 4 case GATE_TYPE_BLOB:
714 {
715 char strbuffer[128];
716 4 gate_size_t strused = gate_str_print_uint64(strbuffer, sizeof(strbuffer), src);
717
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (NULL == gate_blob_create((gate_blob_t*)dst, strbuffer, strused))
718 {
719 return GATE_RESULT_FAILED;
720 }
721 4 break;
722 }
723 default:
724 return GATE_RESULT_NOTSUPPORTED;
725 }
726 92 return GATE_RESULT_OK;
727 }
728 46 gate_result_t gate_value_save_real64(gate_real64_t src, gate_type_id_t dst_type, void* dst)
729 {
730
14/14
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 20 times.
46 switch (dst_type)
731 {
732 2 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = gate_math_iszero(src) ? true : false; break;
733 2 case GATE_TYPE_I8: *((gate_int8_t*)dst) = (gate_int8_t)src; break;
734 2 case GATE_TYPE_I16: *((gate_int16_t*)dst) = (gate_int16_t)src; break;
735 2 case GATE_TYPE_I32: *((gate_int32_t*)dst) = (gate_int32_t)src; break;
736 2 case GATE_TYPE_I64: *((gate_int64_t*)dst) = (gate_int64_t)src; break;
737 2 case GATE_TYPE_UI8: *((gate_uint8_t*)dst) = (gate_uint8_t)src; break;
738 2 case GATE_TYPE_UI16: *((gate_uint16_t*)dst) = (gate_uint16_t)src; break;
739 2 case GATE_TYPE_UI32: *((gate_uint32_t*)dst) = (gate_uint32_t)src; break;
740 2 case GATE_TYPE_UI64: *((gate_uint64_t*)dst) = (gate_uint64_t)src; break;
741 2 case GATE_TYPE_R32: *((gate_real32_t*)dst) = (gate_real32_t)src; break;
742 2 case GATE_TYPE_R64: *((gate_real64_t*)dst) = (gate_real64_t)src; break;
743 2 case GATE_TYPE_ADDRESS: *((gate_uintptr_t*)dst) = (gate_uintptr_t)src; break;
744 2 case GATE_TYPE_STRING:
745 {
746 char strbuffer[128];
747 2 gate_size_t strused = gate_str_print_real(strbuffer, sizeof(strbuffer), src, 0, 6, 0);
748
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (NULL == gate_string_create((gate_string_t*)dst, strbuffer, strused))
749 {
750 return GATE_RESULT_FAILED;
751 }
752 2 break;
753 }
754 20 default:
755 20 return gate_value_save_int64((gate_int64_t)src, dst_type, dst);
756 }
757 26 return GATE_RESULT_OK;
758 }
759
760 23 gate_result_t gate_value_save_bool(gate_bool_t src, gate_type_id_t dst_type, void* dst)
761 {
762
23/24
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
23 switch (dst_type)
763 {
764 1 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = src ? true : false; break;
765 1 case GATE_TYPE_I8: *((gate_int8_t*)dst) = src ? 1 : 0; break;
766 1 case GATE_TYPE_I16: *((gate_int16_t*)dst) = src ? 1 : 0; break;
767 1 case GATE_TYPE_I32: *((gate_int32_t*)dst) = src ? 1 : 0; break;
768 1 case GATE_TYPE_I64: *((gate_int64_t*)dst) = src ? 1 : 0; break;
769 1 case GATE_TYPE_UI8: *((gate_uint8_t*)dst) = src ? 1 : 0; break;
770 1 case GATE_TYPE_UI16: *((gate_uint16_t*)dst) = src ? 1 : 0; break;
771 1 case GATE_TYPE_UI32: *((gate_uint32_t*)dst) = src ? 1 : 0; break;
772 1 case GATE_TYPE_UI64: *((gate_uint64_t*)dst) = src ? 1 : 0; break;
773
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_R32: *((gate_real32_t*)dst) = src ? 1.0f : 0.0f; break;
774
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_R64: *((gate_real64_t*)dst) = src ? 1.0 : 0.0; break;
775 1 case GATE_TYPE_ADDRESS: *((gate_uintptr_t*)dst) = src ? 1 : 0; break;
776
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_DATAPTR: *((gate_dataptr_t*)dst) = src ? ((gate_dataptr_t*)1) : NULL; break;
777 1 case GATE_TYPE_FUNCPTR: *((gate_funcptr_t*)dst) = NULL; break;
778
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_CSTR: *((gate_cstr_t*)dst) = src ? "true" : "false"; break;
779
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_WSTR: *((gate_wstr_t*)dst) = src ? L"true" : L"false"; break;
780 1 case GATE_TYPE_GUID: gate_mem_clear(dst, sizeof(gate_guid_t)); break;
781 1 case GATE_TYPE_DATE: gate_mem_clear(dst, sizeof(gate_date_t)); break;
782 1 case GATE_TYPE_DAYTIME: gate_mem_clear(dst, sizeof(gate_daytime_t)); break;
783 1 case GATE_TYPE_DATETIME:gate_mem_clear(dst, sizeof(gate_datetime_t)); break;
784 1 case GATE_TYPE_TIME: gate_mem_clear(dst, sizeof(gate_time_t)); break;
785
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 case GATE_TYPE_STRING: gate_string_create_static_len((gate_string_t*)dst, src ? "true" : "false", src ? 4 : 5); break;
786
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 case GATE_TYPE_BLOB: gate_blob_create_static((gate_blob_t*)dst, src ? "true" : NULL, src ? 4 : 0); break;
787 default:
788 return GATE_RESULT_NOTSUPPORTED;
789 }
790 23 return GATE_RESULT_OK;
791 }
792
793 23 gate_result_t gate_value_save_int8(gate_int8_t src, gate_type_id_t dst_type, void* dst)
794 {
795 23 return gate_value_save_int64(src, dst_type, dst);
796 }
797 23 gate_result_t gate_value_save_int16(gate_int16_t src, gate_type_id_t dst_type, void* dst)
798 {
799 23 return gate_value_save_int64(src, dst_type, dst);
800 }
801 23 gate_result_t gate_value_save_int32(gate_int32_t src, gate_type_id_t dst_type, void* dst)
802 {
803 23 return gate_value_save_int64(src, dst_type, dst);
804 }
805 23 gate_result_t gate_value_save_uint8(gate_uint8_t src, gate_type_id_t dst_type, void* dst)
806 {
807 23 return gate_value_save_uint64(src, dst_type, dst);
808 }
809 23 gate_result_t gate_value_save_uint16(gate_uint16_t src, gate_type_id_t dst_type, void* dst)
810 {
811 23 return gate_value_save_uint64(src, dst_type, dst);
812 }
813 23 gate_result_t gate_value_save_uint32(gate_uint32_t src, gate_type_id_t dst_type, void* dst)
814 {
815 23 return gate_value_save_uint64(src, dst_type, dst);
816 }
817 23 gate_result_t gate_value_save_real32(gate_real32_t src, gate_type_id_t dst_type, void* dst)
818 {
819 23 return gate_value_save_real64((gate_real64_t)src, dst_type, dst);
820 }
821
822 30 gate_result_t gate_value_save_string(gate_string_t const* src, gate_type_id_t dst_type, void* dst)
823 {
824 30 gate_int64_t i64 = 0;
825 30 gate_uint64_t ui64 = 0;
826 30 gate_real64_t r64 = 0.0;
827
23/24
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 2 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 20 taken 2 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
30 switch (dst_type)
828 {
829
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_BOOL: if (src) gate_str_parse_int64(src->str, src->length, &i64); *((gate_bool_t*)dst) = i64 != 0; break;
830
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_I8: if (src) gate_str_parse_int64(src->str, src->length, &i64); *((gate_int8_t*)dst) = (gate_int8_t)i64; break;
831
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_I16: if (src) gate_str_parse_int64(src->str, src->length, &i64); *((gate_int16_t*)dst) = (gate_int16_t)i64; break;
832
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_I32: if (src) gate_str_parse_int64(src->str, src->length, &i64); *((gate_int32_t*)dst) = (gate_int32_t)i64; break;
833
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_I64: if (src) gate_str_parse_int64(src->str, src->length, &i64); *((gate_int64_t*)dst) = (gate_int64_t)i64; break;
834
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_UI8: if (src) gate_str_parse_uint64(src->str, src->length, &ui64); *((gate_uint8_t*)dst) = (gate_uint8_t)ui64; break;
835
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_UI16: if (src) gate_str_parse_uint64(src->str, src->length, &ui64); *((gate_uint16_t*)dst) = (gate_uint16_t)ui64; break;
836
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_UI32: if (src) gate_str_parse_uint64(src->str, src->length, &ui64); *((gate_uint32_t*)dst) = (gate_uint32_t)ui64; break;
837
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_UI64: if (src) gate_str_parse_uint64(src->str, src->length, &ui64); *((gate_uint64_t*)dst) = (gate_uint64_t)ui64; break;
838
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_R32: if (src) gate_str_parse_real(src->str, src->length, &r64); *((gate_real32_t*)dst) = (gate_real32_t)r64; break;
839
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_R64: if (src) gate_str_parse_real(src->str, src->length, &r64); *((gate_real64_t*)dst) = (gate_real64_t)r64; break;
840
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_ADDRESS: if (src) gate_str_parse_uint64(src->str, src->length, &ui64); *((gate_uintptr_t*)dst) = (gate_uintptr_t)ui64; break;
841
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_DATAPTR: if (src) gate_str_parse_uint64(src->str, src->length, &ui64); *((gate_dataptr_t*)dst) = (gate_dataptr_t)(gate_uintptr_t)ui64; break;
842
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_FUNCPTR: if (src) gate_str_parse_uint64(src->str, src->length, &ui64); *((gate_funcptr_t*)dst) = (gate_funcptr_t)(gate_uintptr_t)ui64; break;
843
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 case GATE_TYPE_GUID: if (src) gate_guid_parse_string(src->str, src->length, (gate_guid_t*)dst); break;
844 2 case GATE_TYPE_CSTR: *((gate_cstr_t*)dst) = src->str; break;
845 2 case GATE_TYPE_WSTR: *((gate_wstr_t*)dst) = NULL; break;
846 2 case GATE_TYPE_DATE:
847 {
848 2 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
849 2 gate_int16_t bias = 0;
850 2 gate_date_parse_string(src->str, src->length, &dt, &bias);
851 2 *((gate_date_t*)dst) = dt.date;
852 2 break;
853 }
854 2 case GATE_TYPE_DAYTIME:
855 {
856 2 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
857 2 gate_int16_t bias = 0;
858 2 gate_date_parse_string(src->str, src->length, &dt, &bias);
859 2 *((gate_daytime_t*)dst) = dt.time;
860 2 break;
861 }
862 2 case GATE_TYPE_DATETIME:
863 {
864 2 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
865 2 gate_int16_t bias = 0;
866 2 gate_date_parse_string(src->str, src->length, &dt, &bias);
867 2 *((gate_datetime_t*)dst) = dt;
868 2 break;
869 }
870 2 case GATE_TYPE_TIME:
871 {
872 2 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
873 2 gate_int16_t bias = 0;
874 2 gate_time_t tm = GATE_TIME_INIT;
875 2 gate_date_parse_string(src->str, src->length, &dt, &bias);
876 2 gate_date_to_time(&dt, &tm);
877 2 tm.bias = bias;
878 2 *((gate_time_t*)dst) = tm;
879 2 break;
880 }
881 1 case GATE_TYPE_STRING:
882 {
883
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_string_clone((gate_string_t*)dst, src))
884 {
885 return GATE_RESULT_FAILED;
886 }
887 1 break;
888 }
889 1 case GATE_TYPE_BLOB:
890 {
891
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_blob_create((gate_blob_t*)dst, gate_string_ptr(src, 0), gate_string_length(src)))
892 {
893 return GATE_RESULT_FAILED;
894 }
895 1 break;
896 }
897 default:
898 {
899 return GATE_RESULT_NOTSUPPORTED;
900 }
901 }
902 30 return GATE_RESULT_OK;
903 }
904
905 #define BLOB_TO_NATIVE_TYPE(ptr_blob, native_type, ptr_target) \
906 do { \
907 gate_size_t blob_len = gate_blob_length(ptr_blob); \
908 if(blob_len > sizeof(native_type)) blob_len = sizeof(native_type); \
909 if(blob_len > 0) { \
910 void const* blob_data = gate_blob_data(ptr_blob); \
911 gate_mem_copy(ptr_target, blob_data, blob_len); \
912 } \
913 return GATE_RESULT_OK; \
914 } while(0)
915
916 23 gate_result_t gate_value_save_blob(gate_blob_t const* src, gate_type_id_t dst_type, void* dst)
917 {
918
2/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
23 if (!src || !dst)
919 {
920 return GATE_RESULT_NULLPOINTER;
921 }
922
923
17/17
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 7 times.
23 switch (dst_type)
924 {
925 1 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = gate_blob_length(src) != 0; return GATE_RESULT_OK; break;
926
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_I8: BLOB_TO_NATIVE_TYPE(src, gate_int8_t, dst); break;
927
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_I16: BLOB_TO_NATIVE_TYPE(src, gate_int16_t, dst); break;
928
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_I32: BLOB_TO_NATIVE_TYPE(src, gate_int32_t, dst); break;
929
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_I64: BLOB_TO_NATIVE_TYPE(src, gate_int64_t, dst); break;
930
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_UI8: BLOB_TO_NATIVE_TYPE(src, gate_uint8_t, dst); break;
931
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_UI16: BLOB_TO_NATIVE_TYPE(src, gate_uint16_t, dst); break;
932
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_UI32: BLOB_TO_NATIVE_TYPE(src, gate_uint32_t, dst); break;
933
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_UI64: BLOB_TO_NATIVE_TYPE(src, gate_uint64_t, dst); break;
934
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_R32: BLOB_TO_NATIVE_TYPE(src, gate_real32_t, dst); break;
935
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_R64: BLOB_TO_NATIVE_TYPE(src, gate_real64_t, dst); break;
936
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_ADDRESS: BLOB_TO_NATIVE_TYPE(src, gate_uintptr_t, dst); break;
937
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_DATAPTR: BLOB_TO_NATIVE_TYPE(src, gate_dataptr_t, dst); break;
938
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 case GATE_TYPE_FUNCPTR: BLOB_TO_NATIVE_TYPE(src, gate_funcptr_t, dst); break;
939 1 case GATE_TYPE_STRING:
940 {
941 1 return (NULL == gate_string_create((gate_string_t*)dst, (char const*)gate_blob_data(src), gate_blob_length(src)))
942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_OUTOFMEMORY : GATE_RESULT_OK;
943 }
944 1 case GATE_TYPE_BLOB:
945 {
946 1 return (NULL == gate_blob_create_clone((gate_blob_t*)dst, src))
947
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_OUTOFMEMORY : GATE_RESULT_OK;
948 }
949 7 default:
950 {
951 gate_string_t str;
952 7 gate_string_create_static_len(&str, (char const*)gate_blob_data(src), gate_blob_length(src));
953 7 return gate_value_save_string(&str, dst_type, dst);
954 }
955 }
956 return GATE_RESULT_FAILED;
957 }
958
959
960
961 gate_result_t gate_value_copy_constructor(void* dest, void const* src)
962 {
963 if (NULL == gate_value_clone((gate_value_t const*)src, (gate_value_t*)dest))
964 {
965 return GATE_RESULT_OUTOFMEMORY;
966 }
967 else
968 {
969 return GATE_RESULT_OK;
970 }
971 }
972 void gate_value_destructor(void* dest)
973 {
974 gate_value_release((gate_value_t*)dest);
975 }
976
977 static gate_uint8_t const false_value = 0;
978 static gate_uint8_t const true_value = 1;
979
980 3 static gate_size_t gate_value_serialize_address(char* dest_buffer, gate_size_t dest_buffer_len, void* ptr)
981 {
982 3 const gate_uint64_t u64 = (gate_uint64_t)(gate_uintptr_t)ptr;
983 3 return gate_serialize_uint64_l(dest_buffer, dest_buffer_len, &u64);
984 }
985 3 static gate_size_t gate_value_deserialize_address(char const* src_buffer, gate_size_t src_buffer_len, void** ptr)
986 {
987 3 gate_uint64_t u64 = 0;
988 3 gate_size_t ret = gate_deserialize_uint64_l(src_buffer, src_buffer_len, &u64);
989
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (ret > 0)
990 {
991 3 *ptr = (void*)(gate_uintptr_t)u64;
992 }
993 3 return ret;
994 }
995
996 23 gate_size_t gate_value_serialize(gate_value_t const* src, char* dest_buffer, gate_size_t dest_buffer_len)
997 {
998 23 gate_size_t ret = 0;
999 23 const gate_uint16_t ser_typeid = (gate_uint16_t)gate_value_type(src);
1000
1001 23 gate_size_t len_payload = 0;
1002 23 gate_size_t len_header = gate_serialize_uint16_l(dest_buffer, dest_buffer_len, &ser_typeid);
1003
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (len_header == 0)
1004 {
1005 /* error case */
1006 return 0;
1007 }
1008
1009 23 dest_buffer += len_header;
1010 23 dest_buffer_len -= len_header;
1011
1012
23/27
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
23 switch (src->value_type)
1013 {
1014 case GATE_TYPE_VOID: { len_payload = gate_serialize_uint8_l(dest_buffer, dest_buffer_len, &false_value); break; }
1015
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_BOOL: { len_payload = gate_serialize_uint8_l(dest_buffer, dest_buffer_len, src->content.bool_value ? &true_value : &false_value); break; }
1016 1 case GATE_TYPE_I8: { len_payload = gate_serialize_int8_l(dest_buffer, dest_buffer_len, &src->content.i8_value); break; }
1017 1 case GATE_TYPE_UI8: { len_payload = gate_serialize_uint8_l(dest_buffer, dest_buffer_len, &src->content.ui8_value); break; }
1018 1 case GATE_TYPE_I16: { len_payload = gate_serialize_int16_l(dest_buffer, dest_buffer_len, &src->content.i16_value); break; }
1019 1 case GATE_TYPE_UI16: { len_payload = gate_serialize_uint16_l(dest_buffer, dest_buffer_len, &src->content.ui16_value); break; }
1020 1 case GATE_TYPE_I32: { len_payload = gate_serialize_int32_l(dest_buffer, dest_buffer_len, &src->content.i32_value); break; }
1021 1 case GATE_TYPE_UI32: { len_payload = gate_serialize_uint32_l(dest_buffer, dest_buffer_len, &src->content.ui32_value); break; }
1022 1 case GATE_TYPE_I64: { len_payload = gate_serialize_int64_l(dest_buffer, dest_buffer_len, &src->content.i64_value); break; }
1023 1 case GATE_TYPE_UI64: { len_payload = gate_serialize_uint64_l(dest_buffer, dest_buffer_len, &src->content.ui64_value); break; }
1024 1 case GATE_TYPE_R32: { len_payload = gate_serialize_real32_l(dest_buffer, dest_buffer_len, &src->content.r32_value); break; }
1025 1 case GATE_TYPE_R64: { len_payload = gate_serialize_real64_l(dest_buffer, dest_buffer_len, &src->content.r64_value); break; }
1026 1 case GATE_TYPE_ADDRESS: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.address_value); break; }
1027 1 case GATE_TYPE_DATAPTR: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.ptr_value); break; }
1028 1 case GATE_TYPE_FUNCPTR: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.address_value); break; }
1029 1 case GATE_TYPE_CSTR:
1030 {
1031 1 gate_size_t len_str = gate_str_length(src->content.cstring_value);
1032 1 gate_uint32_t len_bytes = (gate_uint32_t)(len_str + 1);
1033
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= (len_bytes + 4))
1034 {
1035 1 gate_serialize_uint32_l(dest_buffer, 4, &len_bytes);
1036
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_str > 0)
1037 {
1038 1 gate_mem_copy(&dest_buffer[4], src->content.cstring_value, len_str);
1039 }
1040 1 dest_buffer[4 + len_str] = 0;
1041 1 len_payload = len_bytes + 4;
1042 }
1043 1 break;
1044 }
1045 1 case GATE_TYPE_WSTR:
1046 {
1047 1 gate_size_t len_str = gate_wstr_length(src->content.wstring_value);
1048 1 gate_uint32_t len_bytes = (gate_uint32_t)((len_str + 1) * sizeof(wchar_t));
1049
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= (len_bytes + 4))
1050 {
1051 1 gate_serialize_uint32_l(dest_buffer, 4, &len_bytes);
1052
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_str > 0)
1053 {
1054 1 gate_mem_copy(&dest_buffer[4], src->content.wstring_value, len_str * sizeof(wchar_t));
1055 }
1056 1 gate_mem_clear(&dest_buffer[4 + len_str * sizeof(wchar_t)], sizeof(wchar_t));
1057 1 len_payload = len_bytes + 4;
1058 }
1059 1 break;
1060 }
1061 1 case GATE_TYPE_GUID:
1062 {
1063
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 16)
1064 {
1065 1 gate_serialize_uint32_l(&dest_buffer[0], 4, &src->content.guid_value.item1);
1066 1 gate_serialize_uint16_l(&dest_buffer[4], 2, &src->content.guid_value.item2);
1067 1 gate_serialize_uint16_l(&dest_buffer[6], 2, &src->content.guid_value.item3);
1068 1 gate_mem_copy(&dest_buffer[8], src->content.guid_value.item4, 8);
1069 1 len_payload = 16;
1070 }
1071 1 break;
1072 }
1073 1 case GATE_TYPE_DATE:
1074 {
1075
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 4)
1076 {
1077 1 gate_serialize_uint16_l(&dest_buffer[0], 2, &src->content.date_value.year);
1078 1 gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.date_value.month);
1079 1 gate_serialize_uint8_l(&dest_buffer[3], 1, &src->content.date_value.day);
1080 1 len_payload = 4;
1081 }
1082 1 break;
1083 }
1084 1 case GATE_TYPE_DAYTIME:
1085 {
1086
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 6)
1087 {
1088 char buf[4];
1089 1 const gate_uint32_t micro = src->content.daytime_value.microsecond % 1000000;
1090 1 gate_serialize_uint8_l(&dest_buffer[0], 1, &src->content.daytime_value.hour);
1091 1 gate_serialize_uint8_l(&dest_buffer[1], 1, &src->content.daytime_value.minute);
1092 1 gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.daytime_value.second);
1093 1 gate_serialize_uint32_l(&buf[0], 4, &micro);
1094 1 gate_mem_copy(&dest_buffer[3], &buf[0], 3);
1095 1 len_payload = 6;
1096 }
1097 1 break;
1098 }
1099 1 case GATE_TYPE_DATETIME:
1100 {
1101
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 10)
1102 {
1103 char buf[4];
1104 1 const gate_uint32_t micro = src->content.daytime_value.microsecond % 1000000;
1105 1 gate_serialize_uint16_l(&dest_buffer[0], 2, &src->content.date_value.year);
1106 1 gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.date_value.month);
1107 1 gate_serialize_uint8_l(&dest_buffer[3], 1, &src->content.date_value.day);
1108 1 gate_serialize_uint8_l(&dest_buffer[4], 1, &src->content.daytime_value.hour);
1109 1 gate_serialize_uint8_l(&dest_buffer[5], 1, &src->content.daytime_value.minute);
1110 1 gate_serialize_uint8_l(&dest_buffer[6], 1, &src->content.daytime_value.second);
1111 1 gate_serialize_uint32_l(&buf[0], 4, &micro);
1112 1 gate_mem_copy(&dest_buffer[7], &buf[0], 3);
1113 1 len_payload = 10;
1114 }
1115 1 break;
1116 }
1117 1 case GATE_TYPE_TIME:
1118 {
1119
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 10)
1120 {
1121 1 const gate_int64_t ts = src->content.time_value.timestamp;
1122 1 const gate_int16_t b = src->content.time_value.bias;
1123 1 gate_serialize_int64_l(&dest_buffer[0], 8, &ts);
1124 1 gate_serialize_int16_l(&dest_buffer[8], 2, &b);
1125 1 len_payload = 10;
1126 }
1127 1 break;
1128 }
1129 1 case GATE_TYPE_STRING:
1130 {
1131 1 const gate_uint32_t str_len = (gate_uint32_t)gate_string_length(&src->content.string_value);
1132
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= str_len + 4)
1133 {
1134 1 gate_serialize_uint32_l(&dest_buffer[0], 4, &str_len);
1135 1 gate_mem_copy(&dest_buffer[4], gate_string_ptr(&src->content.string_value, 0), str_len);
1136 1 len_payload = str_len + 4;
1137 }
1138 1 break;
1139 }
1140 case GATE_TYPE_ARRAY:
1141 {
1142 /* type-less arrays are not supported in serialization */
1143 break;
1144 }
1145 1 case GATE_TYPE_BLOB:
1146 {
1147 1 const gate_uint32_t blob_len = (gate_uint32_t)gate_blob_length(&src->content.blob_value);
1148
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= blob_len + 4)
1149 {
1150 1 gate_serialize_uint32_l(&dest_buffer[0], 4, &blob_len);
1151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (blob_len > 0)
1152 {
1153 gate_mem_copy(&dest_buffer[4], gate_blob_data(&src->content.blob_value), blob_len);
1154 }
1155 1 len_payload = blob_len + 4;
1156 }
1157 1 break;
1158 }
1159 case GATE_TYPE_STRUCT:
1160 case GATE_TYPE_OBJECT:
1161 case GATE_TYPE_PROPERTY:
1162
1163 case GATE_TYPE_ARRAYLIST:
1164 case GATE_TYPE_ARRAYLIST_BOOL:
1165 case GATE_TYPE_ARRAYLIST_I8:
1166 case GATE_TYPE_ARRAYLIST_UI8:
1167 case GATE_TYPE_ARRAYLIST_I16:
1168 case GATE_TYPE_ARRAYLIST_UI16:
1169 case GATE_TYPE_ARRAYLIST_I32:
1170 case GATE_TYPE_ARRAYLIST_UI32:
1171 case GATE_TYPE_ARRAYLIST_I64:
1172 case GATE_TYPE_ARRAYLIST_UI64:
1173 case GATE_TYPE_ARRAYLIST_R32:
1174 case GATE_TYPE_ARRAYLIST_R64:
1175 case GATE_TYPE_ARRAYLIST_ADDRESS:
1176
1177 case GATE_TYPE_ARRAYLIST_DATAPTR:
1178 case GATE_TYPE_ARRAYLIST_FUNCPTR:
1179 case GATE_TYPE_ARRAYLIST_CSTR:
1180 case GATE_TYPE_ARRAYLIST_WSTR:
1181 case GATE_TYPE_ARRAYLIST_GUID:
1182 case GATE_TYPE_ARRAYLIST_DATE:
1183 case GATE_TYPE_ARRAYLIST_DAYTIME:
1184 case GATE_TYPE_ARRAYLIST_DATETIME:
1185 case GATE_TYPE_ARRAYLIST_TIME:
1186
1187 case GATE_TYPE_ARRAYLIST_STRING:
1188 case GATE_TYPE_ARRAYLIST_ARRAY:
1189
1190 case GATE_TYPE_ARRAYLIST_STRUCT:
1191 case GATE_TYPE_ARRAYLIST_OBJECT:
1192 case GATE_TYPE_ARRAYLIST_PROPERTY:
1193 break;
1194 }
1195
1196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (len_payload == 0)
1197 {
1198 /* error case */
1199 return 0;
1200 }
1201 else
1202 {
1203 /* success case */
1204 23 return len_header + len_payload;
1205 }
1206 return ret;
1207 }
1208
1209 23 gate_size_t gate_value_deserialize(char const* src_buffer, gate_size_t src_buffer_len, gate_value_t* dst)
1210 {
1211 23 gate_uint16_t ser_type = 0;
1212 23 gate_size_t len_header = gate_deserialize_uint16_l(src_buffer, src_buffer_len, &ser_type);
1213 23 gate_size_t len_payload = 0;
1214
1215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (len_header == 0)
1216 {
1217 /* error case */
1218 return 0;
1219 }
1220
1221 23 src_buffer += len_header;
1222 23 src_buffer_len -= len_header;
1223
1224
23/27
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
23 switch (ser_type)
1225 {
1226 case GATE_TYPE_VOID:
1227 {
1228 gate_uint8_t v = 0;
1229 len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v);
1230 if (len_payload > 0)
1231 {
1232 gate_mem_clear(dst, sizeof(gate_value_t));
1233 }
1234 break;
1235 }
1236 1 case GATE_TYPE_BOOL:
1237 {
1238 1 gate_uint8_t v = 0;
1239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 v = (v != 0) ? true_value : false_value;
1240 1 len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v);
1241
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1242 {
1243 len_payload = 0;
1244 }
1245 1 break;
1246 }
1247 1 case GATE_TYPE_I8:
1248 {
1249 1 gate_int8_t v = 0;
1250 1 len_payload = gate_deserialize_int8_l(src_buffer, src_buffer_len, &v);
1251
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1252 {
1253 len_payload = 0;
1254 }
1255 1 break;
1256 }
1257 1 case GATE_TYPE_UI8:
1258 {
1259 1 gate_uint8_t v = 0;
1260 1 len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v);
1261
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1262 {
1263 len_payload = 0;
1264 }
1265 1 break;
1266 }
1267 1 case GATE_TYPE_I16:
1268 {
1269 1 gate_int16_t v = 0;
1270 1 len_payload = gate_deserialize_int16_l(src_buffer, src_buffer_len, &v);
1271
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1272 {
1273 len_payload = 0;
1274 }
1275 1 break;
1276 }
1277 1 case GATE_TYPE_UI16:
1278 {
1279 1 gate_uint16_t v = 0;
1280 1 len_payload = gate_deserialize_uint16_l(src_buffer, src_buffer_len, &v);
1281
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1282 {
1283 len_payload = 0;
1284 }
1285 1 break;
1286 }
1287 1 case GATE_TYPE_I32:
1288 {
1289 1 gate_int32_t v = 0;
1290 1 len_payload = gate_deserialize_int32_l(src_buffer, src_buffer_len, &v);
1291
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1292 {
1293 len_payload = 0;
1294 }
1295 1 break;
1296 }
1297 1 case GATE_TYPE_UI32:
1298 {
1299 1 gate_uint32_t v = 0;
1300 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &v);
1301
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1302 {
1303 len_payload = 0;
1304 }
1305 1 break;
1306 }
1307 1 case GATE_TYPE_I64:
1308 {
1309 1 gate_int64_t v = 0;
1310 1 len_payload = gate_deserialize_int64_l(src_buffer, src_buffer_len, &v);
1311
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1312 {
1313 len_payload = 0;
1314 }
1315 1 break;
1316 }
1317 1 case GATE_TYPE_UI64:
1318 {
1319 1 gate_uint64_t v = 0;
1320 1 len_payload = gate_deserialize_uint64_l(src_buffer, src_buffer_len, &v);
1321
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1322 {
1323 len_payload = 0;
1324 }
1325 1 break;
1326 }
1327 1 case GATE_TYPE_R32:
1328 {
1329 1 gate_real32_t v = 0.0f;
1330 1 len_payload = gate_deserialize_real32_l(src_buffer, src_buffer_len, &v);
1331
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1332 {
1333 len_payload = 0;
1334 }
1335 1 break;
1336 }
1337 1 case GATE_TYPE_R64:
1338 {
1339 1 gate_real64_t v = 0.0;
1340 1 len_payload = gate_deserialize_real64_l(src_buffer, src_buffer_len, &v);
1341
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if ((len_payload > 0) && (NULL == gate_value_create(ser_type, &v, dst)))
1342 {
1343 len_payload = 0;
1344 }
1345 1 break;
1346 }
1347 1 case GATE_TYPE_ADDRESS:
1348 {
1349 1 void* ptr = NULL;
1350 1 len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr);
1351
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1352 {
1353 1 const gate_uintptr_t v = (gate_uintptr_t)ptr;
1354
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_value_create(ser_type, &v, dst))
1355 {
1356 len_payload = 0;
1357 }
1358 }
1359 1 break;
1360 }
1361 1 case GATE_TYPE_DATAPTR:
1362 {
1363 1 void* ptr = NULL;
1364 1 len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr);
1365
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1366 {
1367 1 const gate_dataptr_t v = (gate_dataptr_t)ptr;
1368
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_value_create(ser_type, &v, dst))
1369 {
1370 len_payload = 0;
1371 }
1372 }
1373 1 break;
1374 }
1375 1 case GATE_TYPE_FUNCPTR:
1376 {
1377 1 void* ptr = NULL;
1378 1 len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr);
1379
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1380 {
1381 1 const gate_funcptr_t v = (gate_funcptr_t)ptr;
1382
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_value_create(ser_type, &v, dst))
1383 {
1384 len_payload = 0;
1385 }
1386 }
1387 1 break;
1388 }
1389 1 case GATE_TYPE_CSTR:
1390 {
1391 1 gate_uint32_t len_str = 0;
1392 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_str);
1393
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1394 {
1395 1 len_payload = 0; /* reset to error case */
1396
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= len_str + 4)
1397 {
1398 1 gate_cstr_t const str = (gate_cstr_t)(src_buffer + 4);
1399
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &str, dst))
1400 {
1401 /* succes case */
1402 1 len_payload = len_str + 4;
1403 }
1404 }
1405 }
1406 1 break;
1407 }
1408 1 case GATE_TYPE_WSTR:
1409 {
1410 1 gate_uint32_t len_str = 0;
1411 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_str);
1412
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1413 {
1414 1 len_payload = 0; /* reset to error case */
1415
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= len_str + 4)
1416 {
1417 1 gate_wstr_t const str = (gate_wstr_t)(src_buffer + 4);
1418
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &str, dst))
1419 {
1420 /* success case */
1421 1 len_payload = len_str + 4;
1422 }
1423 }
1424 }
1425 1 break;
1426 }
1427 1 case GATE_TYPE_GUID:
1428 {
1429
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 16)
1430 {
1431 1 gate_guid_t v = GATE_INIT_EMPTY;
1432 1 gate_deserialize_uint32_l(&src_buffer[0], 4, &v.item1);
1433 1 gate_deserialize_uint16_l(&src_buffer[4], 2, &v.item2);
1434 1 gate_deserialize_uint16_l(&src_buffer[6], 2, &v.item3);
1435 1 gate_mem_copy(&v.item4[0], &src_buffer[8], 8);
1436
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &v, dst))
1437 {
1438 /* success case */
1439 1 len_payload = 16;
1440 }
1441 }
1442 1 break;
1443 }
1444 1 case GATE_TYPE_DATE:
1445 {
1446
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 4)
1447 {
1448 1 gate_date_t dt = GATE_DATE_INIT_EMPTY;
1449 1 gate_deserialize_uint16_l(&src_buffer[0], 2, &dt.year);
1450 1 gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.month);
1451 1 gate_deserialize_uint8_l(&src_buffer[3], 1, &dt.day);
1452
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &dt, dst))
1453 {
1454 /* success case */
1455 1 len_payload = 4;
1456 }
1457 }
1458 1 break;
1459 }
1460 1 case GATE_TYPE_DAYTIME:
1461 {
1462
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 6)
1463 {
1464 1 gate_daytime_t dt = GATE_DAYTIME_INIT_EMPTY;
1465 char buf[4];
1466 1 gate_deserialize_uint8_l(&src_buffer[0], 1, &dt.hour);
1467 1 gate_deserialize_uint8_l(&src_buffer[1], 1, &dt.minute);
1468 1 gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.second);
1469 1 gate_mem_copy(buf, &src_buffer[3], 3);
1470 1 buf[3] = 0;
1471 1 gate_deserialize_uint32_l(buf, 4, &dt.microsecond);
1472
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &dt, dst))
1473 {
1474 /* success case */
1475 1 len_payload = 6;
1476 }
1477 }
1478 1 break;
1479 }
1480 1 case GATE_TYPE_DATETIME:
1481 {
1482
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 10)
1483 {
1484 1 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
1485 char buf[4];
1486 1 gate_deserialize_uint16_l(&src_buffer[0], 2, &dt.date.year);
1487 1 gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.date.month);
1488 1 gate_deserialize_uint8_l(&src_buffer[3], 1, &dt.date.day);
1489 1 gate_deserialize_uint8_l(&src_buffer[4], 1, &dt.time.hour);
1490 1 gate_deserialize_uint8_l(&src_buffer[5], 1, &dt.time.minute);
1491 1 gate_deserialize_uint8_l(&src_buffer[6], 1, &dt.time.second);
1492 1 gate_mem_copy(buf, &src_buffer[7], 3);
1493 1 buf[3] = 0;
1494 1 gate_deserialize_uint32_l(buf, 4, &dt.time.microsecond);
1495
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &dt, dst))
1496 {
1497 /* success case */
1498 1 len_payload = 10;
1499 }
1500 }
1501 1 break;
1502 }
1503 1 case GATE_TYPE_TIME:
1504 {
1505
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 10)
1506 {
1507 1 gate_time_t tm = GATE_TIME_INIT;
1508 1 gate_deserialize_int64_l(&src_buffer[0], 8, &tm.timestamp);
1509 1 gate_deserialize_int16_l(&src_buffer[8], 2, &tm.bias);
1510
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &tm, dst))
1511 {
1512 /* success case */
1513 1 len_payload = 10;
1514 }
1515 }
1516 1 break;
1517 }
1518 1 case GATE_TYPE_STRING:
1519 {
1520 1 gate_uint32_t len_chars = 0;
1521 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_chars);
1522
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload != 0)
1523 {
1524 1 len_payload = 0;
1525
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= len_chars + 4)
1526 {
1527 1 gate_string_t text = GATE_STRING_INIT_EMPTY;
1528
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_string_create(&text, &src_buffer[4], len_chars))
1529 {
1530
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &text, dst))
1531 {
1532 /* success case */
1533 1 len_payload = len_chars + 4;
1534 }
1535 1 gate_string_release(&text);
1536 }
1537 }
1538 }
1539 1 break;
1540 }
1541 case GATE_TYPE_ARRAY:
1542 {
1543 break;
1544 }
1545 1 case GATE_TYPE_BLOB:
1546 {
1547 1 gate_uint32_t len_bytes = 0;
1548 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_bytes);
1549
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload != 0)
1550 {
1551 1 len_payload = 0;
1552
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= len_bytes + 4)
1553 {
1554 1 gate_blob_t blob = GATE_INIT_EMPTY;
1555
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_blob_create(&blob, &src_buffer[4], len_bytes))
1556 {
1557
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &blob, dst))
1558 {
1559 /* success case */
1560 1 len_payload = len_bytes + 4;
1561 }
1562 1 gate_blob_release(&blob);
1563 }
1564 }
1565 }
1566 1 break;
1567 }
1568 case GATE_TYPE_STRUCT:
1569 case GATE_TYPE_OBJECT:
1570 case GATE_TYPE_PROPERTY:
1571
1572 case GATE_TYPE_ARRAYLIST:
1573 case GATE_TYPE_ARRAYLIST_BOOL:
1574 case GATE_TYPE_ARRAYLIST_I8:
1575 case GATE_TYPE_ARRAYLIST_UI8:
1576 case GATE_TYPE_ARRAYLIST_I16:
1577 case GATE_TYPE_ARRAYLIST_UI16:
1578 case GATE_TYPE_ARRAYLIST_I32:
1579 case GATE_TYPE_ARRAYLIST_UI32:
1580 case GATE_TYPE_ARRAYLIST_I64:
1581 case GATE_TYPE_ARRAYLIST_UI64:
1582 case GATE_TYPE_ARRAYLIST_R32:
1583 case GATE_TYPE_ARRAYLIST_R64:
1584 case GATE_TYPE_ARRAYLIST_ADDRESS:
1585
1586 case GATE_TYPE_ARRAYLIST_DATAPTR:
1587 case GATE_TYPE_ARRAYLIST_FUNCPTR:
1588 case GATE_TYPE_ARRAYLIST_CSTR:
1589 case GATE_TYPE_ARRAYLIST_WSTR:
1590 case GATE_TYPE_ARRAYLIST_GUID:
1591 case GATE_TYPE_ARRAYLIST_DATE:
1592 case GATE_TYPE_ARRAYLIST_DAYTIME:
1593 case GATE_TYPE_ARRAYLIST_DATETIME:
1594 case GATE_TYPE_ARRAYLIST_TIME:
1595
1596 case GATE_TYPE_ARRAYLIST_STRING:
1597 case GATE_TYPE_ARRAYLIST_ARRAY:
1598 case GATE_TYPE_ARRAYLIST_BLOB:
1599
1600 case GATE_TYPE_ARRAYLIST_STRUCT:
1601 case GATE_TYPE_ARRAYLIST_OBJECT:
1602 case GATE_TYPE_ARRAYLIST_PROPERTY:
1603 break;
1604 }
1605
1606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (len_payload == 0)
1607 {
1608 /* error case */
1609 return 0;
1610 }
1611 else
1612 {
1613 23 return len_header + len_payload;
1614 }
1615 }
1616