GCC Code Coverage Report


Directory: src/gate/
File: src/gate/values.c
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 822 905 90.8%
Functions: 36 38 94.7%
Branches: 422 632 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 static gate_bool_t const wchar_is_16bit = sizeof(wchar_t) == sizeof(gate_char16_t);
428 gate_string_t* r;
429
430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (wchar_is_16bit)
431 {
432 gate_char16_t const* const text = *((gate_char16_t const* const*)src);
433 r = gate_string_create_utf16(dst, text, gate_str16_length(text));
434 }
435 else
436 {
437 1 gate_char32_t const* const text = *((gate_char32_t const* const*)src);
438 1 r = gate_string_create_utf32(dst, text, gate_str32_length(text));
439 }
440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 return (r == NULL) ? GATE_RESULT_FAILED : GATE_RESULT_OK;
441 }
442 8 case GATE_TYPE_STRING:
443 {
444 8 return (NULL == gate_string_duplicate(dst, (gate_string_t const*)src))
445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
446 }
447 1 case GATE_TYPE_GUID:
448 {
449 1 gate_guid_t const* g = (gate_guid_t const*)src;
450 char buffer[40];
451 1 gate_result_t result = gate_guid_to_string(g, buffer);
452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
453 1 return (NULL == gate_string_create(dst, buffer, gate_str_length_max(buffer, sizeof(buffer))))
454
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
455 }
456 1 case GATE_TYPE_DATE:
457 {
458 char buffer[128];
459 1 gate_size_t len = sizeof(buffer);
460 gate_datetime_t dt;
461 gate_result_t result;
462 1 gate_mem_copy(&dt.date, src, sizeof(gate_date_t));
463 1 gate_mem_clear(&dt.time, sizeof(gate_daytime_t));
464 1 result = gate_date_to_string(&dt, 0, "{YYYY}-{MM}-{DD}", buffer, &len);
465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
466 1 return (NULL == gate_string_create(dst, buffer, len))
467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
468 }
469 1 case GATE_TYPE_DAYTIME:
470 {
471 char buffer[128];
472 1 gate_size_t len = sizeof(buffer);
473 gate_datetime_t dt;
474 gate_result_t result;
475 1 gate_mem_clear(&dt.date, sizeof(gate_date_t));
476 1 gate_mem_copy(&dt.time, src, sizeof(gate_daytime_t));
477 1 result = gate_date_to_string(&dt, 0, "{hh}:{mm}:{ss}.{SSS}", buffer, &len);
478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
479 1 return (NULL == gate_string_create(dst, buffer, len))
480
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
481 }
482 1 case GATE_TYPE_DATETIME:
483 {
484 1 gate_datetime_t const* dt = (gate_datetime_t const*)src;
485 char buffer[128];
486 1 gate_size_t len = sizeof(buffer);
487 1 gate_result_t result = gate_date_to_string(dt, 0, NULL, buffer, &len);
488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
489 1 return (NULL == gate_string_create(dst, buffer, len))
490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
491 }
492 1 case GATE_TYPE_TIME:
493 {
494 1 gate_time_t const* t = (gate_time_t const*)src;
495 char buffer[128];
496 1 gate_size_t len = sizeof(buffer);
497 1 gate_result_t result = gate_time_to_string(t, NULL, buffer, &len);
498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_RETURN_IF_FAILED(result);
499 1 return (NULL == gate_string_create(dst, buffer, len))
500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_FAILED : GATE_RESULT_OK;
501 }
502 31 default:
503 {
504 31 ret = gate_value_load_int64(value_type, src, &tmpint);
505
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 2 times.
31 if (GATE_SUCCEEDED(ret))
506 {
507 29 gate_strbuilder_create(&builder, 16);
508 29 gate_strbuilder_append_int64(&builder, tmpint);
509 29 gate_strbuilder_to_string(&builder, dst);
510 29 gate_strbuilder_release(&builder);
511 }
512 31 return ret;
513 }
514 }
515 }
516
517 23 gate_result_t gate_value_load_blob(gate_type_id_t value_type, void const* src, gate_blob_t* dst)
518 {
519 static gate_blob_t const true_blob = GATE_BLOB_INIT_STATIC("true");
520 23 gate_blob_t* ptr_loaded = NULL;
521
522
2/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
23 if (!src || !dst)
523 {
524 return GATE_RESULT_NULLPOINTER;
525 }
526
527
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)
528 {
529 1 case GATE_TYPE_BOOL: ptr_loaded = gate_blob_create_duplicate(dst, &true_blob); break;
530 1 case GATE_TYPE_I8: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_int8_t)); break;
531 1 case GATE_TYPE_I16: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_int16_t)); break;
532 1 case GATE_TYPE_I32: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_int32_t)); break;
533 1 case GATE_TYPE_I64: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_int64_t)); break;
534 1 case GATE_TYPE_UI8: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uint8_t)); break;
535 1 case GATE_TYPE_UI16: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uint16_t)); break;
536 1 case GATE_TYPE_UI32: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uint32_t)); break;
537 1 case GATE_TYPE_UI64: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uint64_t)); break;
538 1 case GATE_TYPE_R32: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_real32_t)); break;
539 1 case GATE_TYPE_R64: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_real64_t)); break;
540 1 case GATE_TYPE_ADDRESS: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_uintptr_t)); break;
541 1 case GATE_TYPE_DATAPTR: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_dataptr_t)); break;
542 1 case GATE_TYPE_FUNCPTR: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_funcptr_t)); break;
543 1 case GATE_TYPE_CSTR: ptr_loaded = gate_blob_create(dst, *((char const* const*)src), gate_str_length(*((char const* const*)src))); break;
544 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;
545 1 case GATE_TYPE_GUID: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_guid_t)); break;
546 1 case GATE_TYPE_DATE: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_date_t)); break;
547 1 case GATE_TYPE_DAYTIME: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_daytime_t)); break;
548 1 case GATE_TYPE_DATETIME: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_datetime_t)); break;
549 1 case GATE_TYPE_TIME: ptr_loaded = gate_blob_create(dst, src, sizeof(gate_time_t)); break;
550 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;
551 1 case GATE_TYPE_BLOB: ptr_loaded = gate_blob_create_clone(dst, (gate_blob_t const*)src); break;
552 default: return GATE_RESULT_NOTSUPPORTED;
553 }
554
555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 return (ptr_loaded == NULL) ? GATE_RESULT_FAILED : GATE_RESULT_OK;
556 }
557
558
559
560
561 112 gate_result_t gate_value_save_int64(gate_int64_t src, gate_type_id_t dst_type, void* dst)
562 {
563
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)
564 {
565 4 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = (src == 0) ? true : false; break;
566 4 case GATE_TYPE_I8: *((gate_int8_t*)dst) = (gate_int8_t)src; break;
567 4 case GATE_TYPE_I16: *((gate_int16_t*)dst) = (gate_int16_t)src; break;
568 4 case GATE_TYPE_I32: *((gate_int32_t*)dst) = (gate_int32_t)src; break;
569 4 case GATE_TYPE_I64: *((gate_int64_t*)dst) = (gate_int64_t)src; break;
570 4 case GATE_TYPE_UI8: *((gate_uint8_t*)dst) = (gate_uint8_t)src; break;
571 4 case GATE_TYPE_UI16: *((gate_uint16_t*)dst) = (gate_uint16_t)src; break;
572 4 case GATE_TYPE_UI32: *((gate_uint32_t*)dst) = (gate_uint32_t)src; break;
573 4 case GATE_TYPE_UI64: *((gate_uint64_t*)dst) = (gate_uint64_t)src; break;
574 4 case GATE_TYPE_R32: *((gate_real32_t*)dst) = (gate_real32_t)src; break;
575 4 case GATE_TYPE_R64: *((gate_real64_t*)dst) = (gate_real64_t)src; break;
576 4 case GATE_TYPE_ADDRESS: *((gate_uintptr_t*)dst) = (gate_uintptr_t)src; break;
577 6 case GATE_TYPE_DATAPTR: *((gate_dataptr_t*)dst) = (gate_dataptr_t)(gate_intptr_t)src; break;
578 6 case GATE_TYPE_FUNCPTR: *((gate_funcptr_t*)dst) = (gate_funcptr_t)(gate_intptr_t)src; break;
579 6 case GATE_TYPE_CSTR: *((gate_cstr_t*)dst) = NULL; break;
580 6 case GATE_TYPE_WSTR: *((gate_wstr_t*)dst) = NULL; break;
581 6 case GATE_TYPE_GUID: gate_mem_copy(dst, &src, sizeof(src)); break;
582 6 case GATE_TYPE_DATE:
583 {
584 6 gate_time_t tm = GATE_TIME_INIT;
585 6 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
586 6 gate_time_from_unix(src, &tm.timestamp);
587 6 gate_time_to_datetime(&tm, &dt);
588 6 *((gate_date_t*)dst) = dt.date;
589 6 break;
590 }
591 6 case GATE_TYPE_DAYTIME:
592 {
593 6 const gate_uint64_t day_seconds = (gate_uint64_t)src;
594 gate_daytime_t tm;
595 6 gate_uint32_t hour_seconds = (gate_uint32_t)(day_seconds % 3600);
596 6 tm.hour = (gate_uint8_t)(day_seconds / 3600);
597 6 tm.minute = (gate_uint8_t)(hour_seconds / 60);
598 6 tm.second = (gate_uint8_t)(hour_seconds % 60);
599 6 tm.microsecond = 0;
600 6 *((gate_daytime_t*)dst) = tm;
601 6 break;
602 }
603 6 case GATE_TYPE_DATETIME:
604 {
605 6 gate_time_t tm = GATE_TIME_INIT;
606 6 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
607 6 gate_time_from_unix(src, &tm.timestamp);
608 6 gate_time_to_datetime(&tm, &dt);
609 6 *((gate_datetime_t*)dst) = dt;
610 6 break;
611 }
612 6 case GATE_TYPE_TIME:
613 {
614 6 gate_time_t tm = GATE_TIME_INIT;
615 6 gate_time_from_unix(src, &tm.timestamp);
616 6 *((gate_time_t*)dst) = tm;
617 6 break;
618 }
619 4 case GATE_TYPE_STRING:
620 {
621 char strbuffer[128];
622 4 gate_size_t strused = gate_str_print_int64(strbuffer, sizeof(strbuffer), src);
623
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (NULL == gate_string_create((gate_string_t*)dst, strbuffer, strused))
624 {
625 return GATE_RESULT_FAILED;
626 }
627 4 break;
628 }
629 6 case GATE_TYPE_BLOB:
630 {
631 char strbuffer[128];
632 6 gate_size_t strused = gate_str_print_int64(strbuffer, sizeof(strbuffer), src);
633
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (NULL == gate_blob_create((gate_blob_t*)dst, strbuffer, strused))
634 {
635 return GATE_RESULT_FAILED;
636 }
637 6 break;
638 }
639
640 default:
641 {
642 return GATE_RESULT_NOTSUPPORTED;
643 }
644 }
645 112 return GATE_RESULT_OK;
646 }
647 92 gate_result_t gate_value_save_uint64(gate_uint64_t src, gate_type_id_t dst_type, void* dst)
648 {
649
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)
650 {
651 4 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = (src == 0) ? true : false; break;
652 4 case GATE_TYPE_I8: *((gate_int8_t*)dst) = (gate_int8_t)src; break;
653 4 case GATE_TYPE_I16: *((gate_int16_t*)dst) = (gate_int16_t)src; break;
654 4 case GATE_TYPE_I32: *((gate_int32_t*)dst) = (gate_int32_t)src; break;
655 4 case GATE_TYPE_I64: *((gate_int64_t*)dst) = (gate_int64_t)src; break;
656 4 case GATE_TYPE_UI8: *((gate_uint8_t*)dst) = (gate_uint8_t)src; break;
657 4 case GATE_TYPE_UI16: *((gate_uint16_t*)dst) = (gate_uint16_t)src; break;
658 4 case GATE_TYPE_UI32: *((gate_uint32_t*)dst) = (gate_uint32_t)src; break;
659 4 case GATE_TYPE_UI64: *((gate_uint64_t*)dst) = (gate_uint64_t)src; break;
660 4 case GATE_TYPE_R32: *((gate_real32_t*)dst) = (gate_real32_t)(gate_int64_t)src; break;
661 4 case GATE_TYPE_R64: *((gate_real64_t*)dst) = (gate_real64_t)(gate_int64_t)src; break;
662 4 case GATE_TYPE_ADDRESS: *((gate_uintptr_t*)dst) = (gate_uintptr_t)src; break;
663 4 case GATE_TYPE_DATAPTR: *((gate_dataptr_t*)dst) = (gate_dataptr_t)(gate_uintptr_t)src; break;
664 4 case GATE_TYPE_FUNCPTR: *((gate_funcptr_t*)dst) = (gate_funcptr_t)(gate_uintptr_t)src; break;
665 4 case GATE_TYPE_CSTR: *((gate_cstr_t*)dst) = NULL; break;
666 4 case GATE_TYPE_WSTR: *((gate_wstr_t*)dst) = NULL; break;
667 4 case GATE_TYPE_GUID: gate_mem_copy(dst, &src, sizeof(src)); break;
668 4 case GATE_TYPE_DATE:
669 {
670 4 gate_time_t tm = GATE_TIME_INIT;
671 4 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
672 4 gate_time_from_unix((gate_int64_t)src, &tm.timestamp);
673 4 gate_time_to_datetime(&tm, &dt);
674 4 *((gate_date_t*)dst) = dt.date;
675 4 break;
676 }
677 4 case GATE_TYPE_DAYTIME:
678 {
679 4 const gate_uint64_t day_seconds = src;
680 gate_daytime_t tm;
681 4 gate_uint32_t hour_seconds = (gate_uint32_t)(day_seconds % 3600);
682 4 tm.hour = (gate_uint8_t)(day_seconds / 3600);
683 4 tm.minute = (gate_uint8_t)(hour_seconds / 60);
684 4 tm.second = (gate_uint8_t)(hour_seconds % 60);
685 4 tm.microsecond = 0;
686 4 *((gate_daytime_t*)dst) = tm;
687 4 break;
688 }
689 4 case GATE_TYPE_DATETIME:
690 {
691 4 gate_time_t tm = GATE_TIME_INIT;
692 4 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
693 4 gate_time_from_unix((gate_int64_t)src, &tm.timestamp);
694 4 gate_time_to_datetime(&tm, &dt);
695 4 *((gate_datetime_t*)dst) = dt;
696 4 break;
697 }
698 4 case GATE_TYPE_TIME:
699 {
700 4 gate_time_t tm = GATE_TIME_INIT;
701 4 gate_time_from_unix((gate_int64_t)src, &tm.timestamp);
702 4 *((gate_time_t*)dst) = tm;
703 4 break;
704 }
705 4 case GATE_TYPE_STRING:
706 {
707 char strbuffer[128];
708 4 gate_size_t strused = gate_str_print_uint64(strbuffer, sizeof(strbuffer), src);
709
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (NULL == gate_string_create((gate_string_t*)dst, strbuffer, strused))
710 {
711 return GATE_RESULT_FAILED;
712 }
713 4 break;
714 }
715 4 case GATE_TYPE_BLOB:
716 {
717 char strbuffer[128];
718 4 gate_size_t strused = gate_str_print_uint64(strbuffer, sizeof(strbuffer), src);
719
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (NULL == gate_blob_create((gate_blob_t*)dst, strbuffer, strused))
720 {
721 return GATE_RESULT_FAILED;
722 }
723 4 break;
724 }
725 default:
726 return GATE_RESULT_NOTSUPPORTED;
727 }
728 92 return GATE_RESULT_OK;
729 }
730 46 gate_result_t gate_value_save_real64(gate_real64_t src, gate_type_id_t dst_type, void* dst)
731 {
732
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)
733 {
734 2 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = gate_math_iszero(src) ? true : false; break;
735 2 case GATE_TYPE_I8: *((gate_int8_t*)dst) = (gate_int8_t)src; break;
736 2 case GATE_TYPE_I16: *((gate_int16_t*)dst) = (gate_int16_t)src; break;
737 2 case GATE_TYPE_I32: *((gate_int32_t*)dst) = (gate_int32_t)src; break;
738 2 case GATE_TYPE_I64: *((gate_int64_t*)dst) = (gate_int64_t)src; break;
739 2 case GATE_TYPE_UI8: *((gate_uint8_t*)dst) = (gate_uint8_t)src; break;
740 2 case GATE_TYPE_UI16: *((gate_uint16_t*)dst) = (gate_uint16_t)src; break;
741 2 case GATE_TYPE_UI32: *((gate_uint32_t*)dst) = (gate_uint32_t)src; break;
742 2 case GATE_TYPE_UI64: *((gate_uint64_t*)dst) = (gate_uint64_t)src; break;
743 2 case GATE_TYPE_R32: *((gate_real32_t*)dst) = (gate_real32_t)src; break;
744 2 case GATE_TYPE_R64: *((gate_real64_t*)dst) = (gate_real64_t)src; break;
745 2 case GATE_TYPE_ADDRESS: *((gate_uintptr_t*)dst) = (gate_uintptr_t)src; break;
746 2 case GATE_TYPE_STRING:
747 {
748 char strbuffer[128];
749 2 gate_size_t strused = gate_str_print_real(strbuffer, sizeof(strbuffer), src, 0, 6, 0);
750
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (NULL == gate_string_create((gate_string_t*)dst, strbuffer, strused))
751 {
752 return GATE_RESULT_FAILED;
753 }
754 2 break;
755 }
756 20 default:
757 20 return gate_value_save_int64((gate_int64_t)src, dst_type, dst);
758 }
759 26 return GATE_RESULT_OK;
760 }
761
762 23 gate_result_t gate_value_save_bool(gate_bool_t src, gate_type_id_t dst_type, void* dst)
763 {
764
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)
765 {
766 1 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = src ? true : false; break;
767 1 case GATE_TYPE_I8: *((gate_int8_t*)dst) = src ? 1 : 0; break;
768 1 case GATE_TYPE_I16: *((gate_int16_t*)dst) = src ? 1 : 0; break;
769 1 case GATE_TYPE_I32: *((gate_int32_t*)dst) = src ? 1 : 0; break;
770 1 case GATE_TYPE_I64: *((gate_int64_t*)dst) = src ? 1 : 0; break;
771 1 case GATE_TYPE_UI8: *((gate_uint8_t*)dst) = src ? 1 : 0; break;
772 1 case GATE_TYPE_UI16: *((gate_uint16_t*)dst) = src ? 1 : 0; break;
773 1 case GATE_TYPE_UI32: *((gate_uint32_t*)dst) = src ? 1 : 0; break;
774 1 case GATE_TYPE_UI64: *((gate_uint64_t*)dst) = src ? 1 : 0; break;
775
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;
776
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;
777 1 case GATE_TYPE_ADDRESS: *((gate_uintptr_t*)dst) = src ? 1 : 0; break;
778
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;
779 1 case GATE_TYPE_FUNCPTR: *((gate_funcptr_t*)dst) = NULL; break;
780
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 case GATE_TYPE_CSTR: *((gate_cstr_t*)dst) = src ? "true" : "false"; break;
781
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;
782 1 case GATE_TYPE_GUID: gate_mem_clear(dst, sizeof(gate_guid_t)); break;
783 1 case GATE_TYPE_DATE: gate_mem_clear(dst, sizeof(gate_date_t)); break;
784 1 case GATE_TYPE_DAYTIME: gate_mem_clear(dst, sizeof(gate_daytime_t)); break;
785 1 case GATE_TYPE_DATETIME:gate_mem_clear(dst, sizeof(gate_datetime_t)); break;
786 1 case GATE_TYPE_TIME: gate_mem_clear(dst, sizeof(gate_time_t)); break;
787
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;
788
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;
789 default:
790 return GATE_RESULT_NOTSUPPORTED;
791 }
792 23 return GATE_RESULT_OK;
793 }
794
795 23 gate_result_t gate_value_save_int8(gate_int8_t src, gate_type_id_t dst_type, void* dst)
796 {
797 23 return gate_value_save_int64(src, dst_type, dst);
798 }
799 23 gate_result_t gate_value_save_int16(gate_int16_t src, gate_type_id_t dst_type, void* dst)
800 {
801 23 return gate_value_save_int64(src, dst_type, dst);
802 }
803 23 gate_result_t gate_value_save_int32(gate_int32_t src, gate_type_id_t dst_type, void* dst)
804 {
805 23 return gate_value_save_int64(src, dst_type, dst);
806 }
807 23 gate_result_t gate_value_save_uint8(gate_uint8_t src, gate_type_id_t dst_type, void* dst)
808 {
809 23 return gate_value_save_uint64(src, dst_type, dst);
810 }
811 23 gate_result_t gate_value_save_uint16(gate_uint16_t src, gate_type_id_t dst_type, void* dst)
812 {
813 23 return gate_value_save_uint64(src, dst_type, dst);
814 }
815 23 gate_result_t gate_value_save_uint32(gate_uint32_t src, gate_type_id_t dst_type, void* dst)
816 {
817 23 return gate_value_save_uint64(src, dst_type, dst);
818 }
819 23 gate_result_t gate_value_save_real32(gate_real32_t src, gate_type_id_t dst_type, void* dst)
820 {
821 23 return gate_value_save_real64((gate_real64_t)src, dst_type, dst);
822 }
823
824 30 gate_result_t gate_value_save_string(gate_string_t const* src, gate_type_id_t dst_type, void* dst)
825 {
826 30 gate_int64_t i64 = 0;
827 30 gate_uint64_t ui64 = 0;
828 30 gate_real64_t r64 = 0.0;
829
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)
830 {
831
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;
832
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;
833
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;
834
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;
835
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;
836
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;
837
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;
838
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;
839
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;
840
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;
841
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;
842
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;
843
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;
844
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;
845
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;
846 2 case GATE_TYPE_CSTR: *((gate_cstr_t*)dst) = src->str; break;
847 2 case GATE_TYPE_WSTR: *((gate_wstr_t*)dst) = NULL; break;
848 2 case GATE_TYPE_DATE:
849 {
850 2 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
851 2 gate_int16_t bias = 0;
852 2 gate_date_parse_string(src->str, src->length, &dt, &bias);
853 2 *((gate_date_t*)dst) = dt.date;
854 2 break;
855 }
856 2 case GATE_TYPE_DAYTIME:
857 {
858 2 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
859 2 gate_int16_t bias = 0;
860 2 gate_date_parse_string(src->str, src->length, &dt, &bias);
861 2 *((gate_daytime_t*)dst) = dt.time;
862 2 break;
863 }
864 2 case GATE_TYPE_DATETIME:
865 {
866 2 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
867 2 gate_int16_t bias = 0;
868 2 gate_date_parse_string(src->str, src->length, &dt, &bias);
869 2 *((gate_datetime_t*)dst) = dt;
870 2 break;
871 }
872 2 case GATE_TYPE_TIME:
873 {
874 2 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
875 2 gate_int16_t bias = 0;
876 2 gate_time_t tm = GATE_TIME_INIT;
877 2 gate_date_parse_string(src->str, src->length, &dt, &bias);
878 2 gate_date_to_time(&dt, &tm);
879 2 tm.bias = bias;
880 2 *((gate_time_t*)dst) = tm;
881 2 break;
882 }
883 1 case GATE_TYPE_STRING:
884 {
885
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_string_clone((gate_string_t*)dst, src))
886 {
887 return GATE_RESULT_FAILED;
888 }
889 1 break;
890 }
891 1 case GATE_TYPE_BLOB:
892 {
893
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)))
894 {
895 return GATE_RESULT_FAILED;
896 }
897 1 break;
898 }
899 default:
900 {
901 return GATE_RESULT_NOTSUPPORTED;
902 }
903 }
904 30 return GATE_RESULT_OK;
905 }
906
907 #define BLOB_TO_NATIVE_TYPE(ptr_blob, native_type, ptr_target) \
908 do { \
909 gate_size_t blob_len = gate_blob_length(ptr_blob); \
910 if(blob_len > sizeof(native_type)) blob_len = sizeof(native_type); \
911 if(blob_len > 0) { \
912 void const* blob_data = gate_blob_data(ptr_blob); \
913 gate_mem_copy(ptr_target, blob_data, blob_len); \
914 } \
915 return GATE_RESULT_OK; \
916 } while(0)
917
918 23 gate_result_t gate_value_save_blob(gate_blob_t const* src, gate_type_id_t dst_type, void* dst)
919 {
920
2/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
23 if (!src || !dst)
921 {
922 return GATE_RESULT_NULLPOINTER;
923 }
924
925
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)
926 {
927 1 case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = gate_blob_length(src) != 0; return GATE_RESULT_OK;
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_I8: BLOB_TO_NATIVE_TYPE(src, gate_int8_t, dst);
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_I16: BLOB_TO_NATIVE_TYPE(src, gate_int16_t, dst);
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_I32: BLOB_TO_NATIVE_TYPE(src, gate_int32_t, dst);
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_I64: BLOB_TO_NATIVE_TYPE(src, gate_int64_t, dst);
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_UI8: BLOB_TO_NATIVE_TYPE(src, gate_uint8_t, dst);
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_UI16: BLOB_TO_NATIVE_TYPE(src, gate_uint16_t, dst);
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_UI32: BLOB_TO_NATIVE_TYPE(src, gate_uint32_t, dst);
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_UI64: BLOB_TO_NATIVE_TYPE(src, gate_uint64_t, dst);
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_R32: BLOB_TO_NATIVE_TYPE(src, gate_real32_t, dst);
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_R64: BLOB_TO_NATIVE_TYPE(src, gate_real64_t, dst);
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_ADDRESS: BLOB_TO_NATIVE_TYPE(src, gate_uintptr_t, dst);
939
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);
940
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);
941 1 case GATE_TYPE_STRING:
942 {
943 1 return (NULL == gate_string_create((gate_string_t*)dst, (char const*)gate_blob_data(src), gate_blob_length(src)))
944
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_OUTOFMEMORY : GATE_RESULT_OK;
945 }
946 1 case GATE_TYPE_BLOB:
947 {
948 1 return (NULL == gate_blob_create_clone((gate_blob_t*)dst, src))
949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ? GATE_RESULT_OUTOFMEMORY : GATE_RESULT_OK;
950 }
951 7 default:
952 {
953 gate_string_t str;
954 7 gate_string_create_static_len(&str, (char const*)gate_blob_data(src), gate_blob_length(src));
955 7 return gate_value_save_string(&str, dst_type, dst);
956 }
957 }
958 }
959
960
961
962 gate_result_t gate_value_copy_constructor(void* dest, void const* src)
963 {
964 if (NULL == gate_value_clone((gate_value_t const*)src, (gate_value_t*)dest))
965 {
966 return GATE_RESULT_OUTOFMEMORY;
967 }
968 else
969 {
970 return GATE_RESULT_OK;
971 }
972 }
973 void gate_value_destructor(void* dest)
974 {
975 gate_value_release((gate_value_t*)dest);
976 }
977
978 static gate_uint8_t const false_value = 0;
979 static gate_uint8_t const true_value = 1;
980
981 3 static gate_size_t gate_value_serialize_address(char* dest_buffer, gate_size_t dest_buffer_len, void* ptr)
982 {
983 3 const gate_uint64_t u64 = (gate_uint64_t)(gate_uintptr_t)ptr;
984 3 return gate_serialize_uint64_l(dest_buffer, dest_buffer_len, &u64);
985 }
986 3 static gate_size_t gate_value_deserialize_address(char const* src_buffer, gate_size_t src_buffer_len, void** ptr)
987 {
988 3 gate_uint64_t u64 = 0;
989 3 gate_size_t ret = gate_deserialize_uint64_l(src_buffer, src_buffer_len, &u64);
990
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (ret > 0)
991 {
992 3 *ptr = (void*)(gate_uintptr_t)u64;
993 }
994 3 return ret;
995 }
996
997 23 gate_size_t gate_value_serialize(gate_value_t const* src, char* dest_buffer, gate_size_t dest_buffer_len)
998 {
999 23 gate_size_t ret = 0;
1000 23 const gate_uint16_t ser_typeid = (gate_uint16_t)gate_value_type(src);
1001
1002 23 gate_size_t len_payload = 0;
1003 23 gate_size_t len_header = gate_serialize_uint16_l(dest_buffer, dest_buffer_len, &ser_typeid);
1004
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (len_header == 0)
1005 {
1006 /* error case */
1007 return 0;
1008 }
1009
1010 23 dest_buffer += len_header;
1011 23 dest_buffer_len -= len_header;
1012
1013
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)
1014 {
1015 case GATE_TYPE_VOID: { len_payload = gate_serialize_uint8_l(dest_buffer, dest_buffer_len, &false_value); break; }
1016
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; }
1017 1 case GATE_TYPE_I8: { len_payload = gate_serialize_int8_l(dest_buffer, dest_buffer_len, &src->content.i8_value); break; }
1018 1 case GATE_TYPE_UI8: { len_payload = gate_serialize_uint8_l(dest_buffer, dest_buffer_len, &src->content.ui8_value); break; }
1019 1 case GATE_TYPE_I16: { len_payload = gate_serialize_int16_l(dest_buffer, dest_buffer_len, &src->content.i16_value); break; }
1020 1 case GATE_TYPE_UI16: { len_payload = gate_serialize_uint16_l(dest_buffer, dest_buffer_len, &src->content.ui16_value); break; }
1021 1 case GATE_TYPE_I32: { len_payload = gate_serialize_int32_l(dest_buffer, dest_buffer_len, &src->content.i32_value); break; }
1022 1 case GATE_TYPE_UI32: { len_payload = gate_serialize_uint32_l(dest_buffer, dest_buffer_len, &src->content.ui32_value); break; }
1023 1 case GATE_TYPE_I64: { len_payload = gate_serialize_int64_l(dest_buffer, dest_buffer_len, &src->content.i64_value); break; }
1024 1 case GATE_TYPE_UI64: { len_payload = gate_serialize_uint64_l(dest_buffer, dest_buffer_len, &src->content.ui64_value); break; }
1025 1 case GATE_TYPE_R32: { len_payload = gate_serialize_real32_l(dest_buffer, dest_buffer_len, &src->content.r32_value); break; }
1026 1 case GATE_TYPE_R64: { len_payload = gate_serialize_real64_l(dest_buffer, dest_buffer_len, &src->content.r64_value); break; }
1027 1 case GATE_TYPE_ADDRESS: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.address_value); break; }
1028 1 case GATE_TYPE_DATAPTR: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.ptr_value); break; }
1029 1 case GATE_TYPE_FUNCPTR: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.address_value); break; }
1030 1 case GATE_TYPE_CSTR:
1031 {
1032 1 gate_size_t len_str = gate_str_length(src->content.cstring_value);
1033 1 gate_uint32_t len_bytes = (gate_uint32_t)(len_str + 1);
1034
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= (len_bytes + 4))
1035 {
1036 1 gate_serialize_uint32_l(dest_buffer, 4, &len_bytes);
1037
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_str > 0)
1038 {
1039 1 gate_mem_copy(&dest_buffer[4], src->content.cstring_value, len_str);
1040 }
1041 1 dest_buffer[4 + len_str] = 0;
1042 1 len_payload = len_bytes + 4;
1043 }
1044 1 break;
1045 }
1046 1 case GATE_TYPE_WSTR:
1047 {
1048 1 gate_size_t len_str = gate_wstr_length(src->content.wstring_value);
1049 1 gate_uint32_t len_bytes = (gate_uint32_t)((len_str + 1) * sizeof(wchar_t));
1050
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= (len_bytes + 4))
1051 {
1052 1 gate_serialize_uint32_l(dest_buffer, 4, &len_bytes);
1053
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_str > 0)
1054 {
1055 1 gate_mem_copy(&dest_buffer[4], src->content.wstring_value, len_str * sizeof(wchar_t));
1056 }
1057 1 gate_mem_clear(&dest_buffer[4 + len_str * sizeof(wchar_t)], sizeof(wchar_t));
1058 1 len_payload = len_bytes + 4;
1059 }
1060 1 break;
1061 }
1062 1 case GATE_TYPE_GUID:
1063 {
1064
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 16)
1065 {
1066 1 gate_serialize_uint32_l(&dest_buffer[0], 4, &src->content.guid_value.item1);
1067 1 gate_serialize_uint16_l(&dest_buffer[4], 2, &src->content.guid_value.item2);
1068 1 gate_serialize_uint16_l(&dest_buffer[6], 2, &src->content.guid_value.item3);
1069 1 gate_mem_copy(&dest_buffer[8], src->content.guid_value.item4, 8);
1070 1 len_payload = 16;
1071 }
1072 1 break;
1073 }
1074 1 case GATE_TYPE_DATE:
1075 {
1076
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 4)
1077 {
1078 1 gate_serialize_uint16_l(&dest_buffer[0], 2, &src->content.date_value.year);
1079 1 gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.date_value.month);
1080 1 gate_serialize_uint8_l(&dest_buffer[3], 1, &src->content.date_value.day);
1081 1 len_payload = 4;
1082 }
1083 1 break;
1084 }
1085 1 case GATE_TYPE_DAYTIME:
1086 {
1087
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 6)
1088 {
1089 char buf[4];
1090 1 const gate_uint32_t micro = src->content.daytime_value.microsecond % 1000000;
1091 1 gate_serialize_uint8_l(&dest_buffer[0], 1, &src->content.daytime_value.hour);
1092 1 gate_serialize_uint8_l(&dest_buffer[1], 1, &src->content.daytime_value.minute);
1093 1 gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.daytime_value.second);
1094 1 gate_serialize_uint32_l(&buf[0], 4, &micro);
1095 1 gate_mem_copy(&dest_buffer[3], &buf[0], 3);
1096 1 len_payload = 6;
1097 }
1098 1 break;
1099 }
1100 1 case GATE_TYPE_DATETIME:
1101 {
1102
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 10)
1103 {
1104 char buf[4];
1105 1 const gate_uint32_t micro = src->content.daytime_value.microsecond % 1000000;
1106 1 gate_serialize_uint16_l(&dest_buffer[0], 2, &src->content.date_value.year);
1107 1 gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.date_value.month);
1108 1 gate_serialize_uint8_l(&dest_buffer[3], 1, &src->content.date_value.day);
1109 1 gate_serialize_uint8_l(&dest_buffer[4], 1, &src->content.daytime_value.hour);
1110 1 gate_serialize_uint8_l(&dest_buffer[5], 1, &src->content.daytime_value.minute);
1111 1 gate_serialize_uint8_l(&dest_buffer[6], 1, &src->content.daytime_value.second);
1112 1 gate_serialize_uint32_l(&buf[0], 4, &micro);
1113 1 gate_mem_copy(&dest_buffer[7], &buf[0], 3);
1114 1 len_payload = 10;
1115 }
1116 1 break;
1117 }
1118 1 case GATE_TYPE_TIME:
1119 {
1120
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= 10)
1121 {
1122 1 const gate_int64_t ts = src->content.time_value.timestamp;
1123 1 const gate_int16_t b = src->content.time_value.bias;
1124 1 gate_serialize_int64_l(&dest_buffer[0], 8, &ts);
1125 1 gate_serialize_int16_l(&dest_buffer[8], 2, &b);
1126 1 len_payload = 10;
1127 }
1128 1 break;
1129 }
1130 1 case GATE_TYPE_STRING:
1131 {
1132 1 const gate_uint32_t str_len = (gate_uint32_t)gate_string_length(&src->content.string_value);
1133
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= str_len + 4)
1134 {
1135 1 gate_serialize_uint32_l(&dest_buffer[0], 4, &str_len);
1136 1 gate_mem_copy(&dest_buffer[4], gate_string_ptr(&src->content.string_value, 0), str_len);
1137 1 len_payload = str_len + 4;
1138 }
1139 1 break;
1140 }
1141 case GATE_TYPE_ARRAY:
1142 {
1143 /* type-less arrays are not supported in serialization */
1144 break;
1145 }
1146 1 case GATE_TYPE_BLOB:
1147 {
1148 1 const gate_uint32_t blob_len = (gate_uint32_t)gate_blob_length(&src->content.blob_value);
1149
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (dest_buffer_len >= blob_len + 4)
1150 {
1151 1 gate_serialize_uint32_l(&dest_buffer[0], 4, &blob_len);
1152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (blob_len > 0)
1153 {
1154 gate_mem_copy(&dest_buffer[4], gate_blob_data(&src->content.blob_value), blob_len);
1155 }
1156 1 len_payload = blob_len + 4;
1157 }
1158 1 break;
1159 }
1160 case GATE_TYPE_STRUCT:
1161 case GATE_TYPE_OBJECT:
1162 case GATE_TYPE_PROPERTY:
1163
1164 case GATE_TYPE_ARRAYLIST:
1165 case GATE_TYPE_ARRAYLIST_BOOL:
1166 case GATE_TYPE_ARRAYLIST_I8:
1167 case GATE_TYPE_ARRAYLIST_UI8:
1168 case GATE_TYPE_ARRAYLIST_I16:
1169 case GATE_TYPE_ARRAYLIST_UI16:
1170 case GATE_TYPE_ARRAYLIST_I32:
1171 case GATE_TYPE_ARRAYLIST_UI32:
1172 case GATE_TYPE_ARRAYLIST_I64:
1173 case GATE_TYPE_ARRAYLIST_UI64:
1174 case GATE_TYPE_ARRAYLIST_R32:
1175 case GATE_TYPE_ARRAYLIST_R64:
1176 case GATE_TYPE_ARRAYLIST_ADDRESS:
1177
1178 case GATE_TYPE_ARRAYLIST_DATAPTR:
1179 case GATE_TYPE_ARRAYLIST_FUNCPTR:
1180 case GATE_TYPE_ARRAYLIST_CSTR:
1181 case GATE_TYPE_ARRAYLIST_WSTR:
1182 case GATE_TYPE_ARRAYLIST_GUID:
1183 case GATE_TYPE_ARRAYLIST_DATE:
1184 case GATE_TYPE_ARRAYLIST_DAYTIME:
1185 case GATE_TYPE_ARRAYLIST_DATETIME:
1186 case GATE_TYPE_ARRAYLIST_TIME:
1187
1188 case GATE_TYPE_ARRAYLIST_STRING:
1189 case GATE_TYPE_ARRAYLIST_ARRAY:
1190
1191 case GATE_TYPE_ARRAYLIST_STRUCT:
1192 case GATE_TYPE_ARRAYLIST_OBJECT:
1193 case GATE_TYPE_ARRAYLIST_PROPERTY:
1194 break;
1195 }
1196
1197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (len_payload == 0)
1198 {
1199 /* error case */
1200 return 0;
1201 }
1202 else
1203 {
1204 /* success case */
1205 23 return len_header + len_payload;
1206 }
1207 return ret;
1208 }
1209
1210 23 gate_size_t gate_value_deserialize(char const* src_buffer, gate_size_t src_buffer_len, gate_value_t* dst)
1211 {
1212 23 gate_uint16_t ser_type = 0;
1213 23 gate_size_t len_header = gate_deserialize_uint16_l(src_buffer, src_buffer_len, &ser_type);
1214 23 gate_size_t len_payload = 0;
1215
1216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (len_header == 0)
1217 {
1218 /* error case */
1219 return 0;
1220 }
1221
1222 23 src_buffer += len_header;
1223 23 src_buffer_len -= len_header;
1224
1225
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)
1226 {
1227 case GATE_TYPE_VOID:
1228 {
1229 gate_uint8_t v = 0;
1230 len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v);
1231 if (len_payload > 0)
1232 {
1233 gate_mem_clear(dst, sizeof(gate_value_t));
1234 }
1235 break;
1236 }
1237 1 case GATE_TYPE_BOOL:
1238 {
1239 1 gate_uint8_t v = 0;
1240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 v = (v != 0) ? true_value : false_value;
1241 1 len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v);
1242
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)))
1243 {
1244 len_payload = 0;
1245 }
1246 1 break;
1247 }
1248 1 case GATE_TYPE_I8:
1249 {
1250 1 gate_int8_t v = 0;
1251 1 len_payload = gate_deserialize_int8_l(src_buffer, src_buffer_len, &v);
1252
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)))
1253 {
1254 len_payload = 0;
1255 }
1256 1 break;
1257 }
1258 1 case GATE_TYPE_UI8:
1259 {
1260 1 gate_uint8_t v = 0;
1261 1 len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v);
1262
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)))
1263 {
1264 len_payload = 0;
1265 }
1266 1 break;
1267 }
1268 1 case GATE_TYPE_I16:
1269 {
1270 1 gate_int16_t v = 0;
1271 1 len_payload = gate_deserialize_int16_l(src_buffer, src_buffer_len, &v);
1272
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)))
1273 {
1274 len_payload = 0;
1275 }
1276 1 break;
1277 }
1278 1 case GATE_TYPE_UI16:
1279 {
1280 1 gate_uint16_t v = 0;
1281 1 len_payload = gate_deserialize_uint16_l(src_buffer, src_buffer_len, &v);
1282
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)))
1283 {
1284 len_payload = 0;
1285 }
1286 1 break;
1287 }
1288 1 case GATE_TYPE_I32:
1289 {
1290 1 gate_int32_t v = 0;
1291 1 len_payload = gate_deserialize_int32_l(src_buffer, src_buffer_len, &v);
1292
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)))
1293 {
1294 len_payload = 0;
1295 }
1296 1 break;
1297 }
1298 1 case GATE_TYPE_UI32:
1299 {
1300 1 gate_uint32_t v = 0;
1301 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &v);
1302
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)))
1303 {
1304 len_payload = 0;
1305 }
1306 1 break;
1307 }
1308 1 case GATE_TYPE_I64:
1309 {
1310 1 gate_int64_t v = 0;
1311 1 len_payload = gate_deserialize_int64_l(src_buffer, src_buffer_len, &v);
1312
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)))
1313 {
1314 len_payload = 0;
1315 }
1316 1 break;
1317 }
1318 1 case GATE_TYPE_UI64:
1319 {
1320 1 gate_uint64_t v = 0;
1321 1 len_payload = gate_deserialize_uint64_l(src_buffer, src_buffer_len, &v);
1322
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)))
1323 {
1324 len_payload = 0;
1325 }
1326 1 break;
1327 }
1328 1 case GATE_TYPE_R32:
1329 {
1330 1 gate_real32_t v = 0.0f;
1331 1 len_payload = gate_deserialize_real32_l(src_buffer, src_buffer_len, &v);
1332
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)))
1333 {
1334 len_payload = 0;
1335 }
1336 1 break;
1337 }
1338 1 case GATE_TYPE_R64:
1339 {
1340 1 gate_real64_t v = 0.0;
1341 1 len_payload = gate_deserialize_real64_l(src_buffer, src_buffer_len, &v);
1342
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)))
1343 {
1344 len_payload = 0;
1345 }
1346 1 break;
1347 }
1348 1 case GATE_TYPE_ADDRESS:
1349 {
1350 1 void* ptr = NULL;
1351 1 len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr);
1352
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1353 {
1354 1 const gate_uintptr_t v = (gate_uintptr_t)ptr;
1355
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_value_create(ser_type, &v, dst))
1356 {
1357 len_payload = 0;
1358 }
1359 }
1360 1 break;
1361 }
1362 1 case GATE_TYPE_DATAPTR:
1363 {
1364 1 void* ptr = NULL;
1365 1 len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr);
1366
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1367 {
1368 1 const gate_dataptr_t v = (gate_dataptr_t)ptr;
1369
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_value_create(ser_type, &v, dst))
1370 {
1371 len_payload = 0;
1372 }
1373 }
1374 1 break;
1375 }
1376 1 case GATE_TYPE_FUNCPTR:
1377 {
1378 1 void* ptr = NULL;
1379 1 len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr);
1380
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1381 {
1382 1 const gate_funcptr_t v = (gate_funcptr_t)ptr;
1383
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_value_create(ser_type, &v, dst))
1384 {
1385 len_payload = 0;
1386 }
1387 }
1388 1 break;
1389 }
1390 1 case GATE_TYPE_CSTR:
1391 {
1392 1 gate_uint32_t len_str = 0;
1393 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_str);
1394
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1395 {
1396 1 len_payload = 0; /* reset to error case */
1397
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= len_str + 4)
1398 {
1399 1 gate_cstr_t const str = (gate_cstr_t)(src_buffer + 4);
1400
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &str, dst))
1401 {
1402 /* succes case */
1403 1 len_payload = len_str + 4;
1404 }
1405 }
1406 }
1407 1 break;
1408 }
1409 1 case GATE_TYPE_WSTR:
1410 {
1411 1 gate_uint32_t len_str = 0;
1412 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_str);
1413
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload > 0)
1414 {
1415 1 len_payload = 0; /* reset to error case */
1416
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= len_str + 4)
1417 {
1418 1 gate_wstr_t const str = (gate_wstr_t)(src_buffer + 4);
1419
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &str, dst))
1420 {
1421 /* success case */
1422 1 len_payload = len_str + 4;
1423 }
1424 }
1425 }
1426 1 break;
1427 }
1428 1 case GATE_TYPE_GUID:
1429 {
1430
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 16)
1431 {
1432 1 gate_guid_t v = GATE_INIT_EMPTY;
1433 1 gate_deserialize_uint32_l(&src_buffer[0], 4, &v.item1);
1434 1 gate_deserialize_uint16_l(&src_buffer[4], 2, &v.item2);
1435 1 gate_deserialize_uint16_l(&src_buffer[6], 2, &v.item3);
1436 1 gate_mem_copy(&v.item4[0], &src_buffer[8], 8);
1437
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &v, dst))
1438 {
1439 /* success case */
1440 1 len_payload = 16;
1441 }
1442 }
1443 1 break;
1444 }
1445 1 case GATE_TYPE_DATE:
1446 {
1447
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 4)
1448 {
1449 1 gate_date_t dt = GATE_DATE_INIT_EMPTY;
1450 1 gate_deserialize_uint16_l(&src_buffer[0], 2, &dt.year);
1451 1 gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.month);
1452 1 gate_deserialize_uint8_l(&src_buffer[3], 1, &dt.day);
1453
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &dt, dst))
1454 {
1455 /* success case */
1456 1 len_payload = 4;
1457 }
1458 }
1459 1 break;
1460 }
1461 1 case GATE_TYPE_DAYTIME:
1462 {
1463
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 6)
1464 {
1465 1 gate_daytime_t dt = GATE_DAYTIME_INIT_EMPTY;
1466 char buf[4];
1467 1 gate_deserialize_uint8_l(&src_buffer[0], 1, &dt.hour);
1468 1 gate_deserialize_uint8_l(&src_buffer[1], 1, &dt.minute);
1469 1 gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.second);
1470 1 gate_mem_copy(buf, &src_buffer[3], 3);
1471 1 buf[3] = 0;
1472 1 gate_deserialize_uint32_l(buf, 4, &dt.microsecond);
1473
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &dt, dst))
1474 {
1475 /* success case */
1476 1 len_payload = 6;
1477 }
1478 }
1479 1 break;
1480 }
1481 1 case GATE_TYPE_DATETIME:
1482 {
1483
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 10)
1484 {
1485 1 gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY;
1486 char buf[4];
1487 1 gate_deserialize_uint16_l(&src_buffer[0], 2, &dt.date.year);
1488 1 gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.date.month);
1489 1 gate_deserialize_uint8_l(&src_buffer[3], 1, &dt.date.day);
1490 1 gate_deserialize_uint8_l(&src_buffer[4], 1, &dt.time.hour);
1491 1 gate_deserialize_uint8_l(&src_buffer[5], 1, &dt.time.minute);
1492 1 gate_deserialize_uint8_l(&src_buffer[6], 1, &dt.time.second);
1493 1 gate_mem_copy(buf, &src_buffer[7], 3);
1494 1 buf[3] = 0;
1495 1 gate_deserialize_uint32_l(buf, 4, &dt.time.microsecond);
1496
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &dt, dst))
1497 {
1498 /* success case */
1499 1 len_payload = 10;
1500 }
1501 }
1502 1 break;
1503 }
1504 1 case GATE_TYPE_TIME:
1505 {
1506
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= 10)
1507 {
1508 1 gate_time_t tm = GATE_TIME_INIT;
1509 1 gate_deserialize_int64_l(&src_buffer[0], 8, &tm.timestamp);
1510 1 gate_deserialize_int16_l(&src_buffer[8], 2, &tm.bias);
1511
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &tm, dst))
1512 {
1513 /* success case */
1514 1 len_payload = 10;
1515 }
1516 }
1517 1 break;
1518 }
1519 1 case GATE_TYPE_STRING:
1520 {
1521 1 gate_uint32_t len_chars = 0;
1522 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_chars);
1523
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload != 0)
1524 {
1525 1 len_payload = 0;
1526
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= len_chars + 4)
1527 {
1528 1 gate_string_t text = GATE_STRING_INIT_EMPTY;
1529
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_string_create(&text, &src_buffer[4], len_chars))
1530 {
1531
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &text, dst))
1532 {
1533 /* success case */
1534 1 len_payload = len_chars + 4;
1535 }
1536 1 gate_string_release(&text);
1537 }
1538 }
1539 }
1540 1 break;
1541 }
1542 case GATE_TYPE_ARRAY:
1543 {
1544 break;
1545 }
1546 1 case GATE_TYPE_BLOB:
1547 {
1548 1 gate_uint32_t len_bytes = 0;
1549 1 len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_bytes);
1550
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (len_payload != 0)
1551 {
1552 1 len_payload = 0;
1553
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (src_buffer_len >= len_bytes + 4)
1554 {
1555 1 gate_blob_t blob = GATE_INIT_EMPTY;
1556
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_blob_create(&blob, &src_buffer[4], len_bytes))
1557 {
1558
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (NULL != gate_value_create(ser_type, &blob, dst))
1559 {
1560 /* success case */
1561 1 len_payload = len_bytes + 4;
1562 }
1563 1 gate_blob_release(&blob);
1564 }
1565 }
1566 }
1567 1 break;
1568 }
1569 case GATE_TYPE_STRUCT:
1570 case GATE_TYPE_OBJECT:
1571 case GATE_TYPE_PROPERTY:
1572
1573 case GATE_TYPE_ARRAYLIST:
1574 case GATE_TYPE_ARRAYLIST_BOOL:
1575 case GATE_TYPE_ARRAYLIST_I8:
1576 case GATE_TYPE_ARRAYLIST_UI8:
1577 case GATE_TYPE_ARRAYLIST_I16:
1578 case GATE_TYPE_ARRAYLIST_UI16:
1579 case GATE_TYPE_ARRAYLIST_I32:
1580 case GATE_TYPE_ARRAYLIST_UI32:
1581 case GATE_TYPE_ARRAYLIST_I64:
1582 case GATE_TYPE_ARRAYLIST_UI64:
1583 case GATE_TYPE_ARRAYLIST_R32:
1584 case GATE_TYPE_ARRAYLIST_R64:
1585 case GATE_TYPE_ARRAYLIST_ADDRESS:
1586
1587 case GATE_TYPE_ARRAYLIST_DATAPTR:
1588 case GATE_TYPE_ARRAYLIST_FUNCPTR:
1589 case GATE_TYPE_ARRAYLIST_CSTR:
1590 case GATE_TYPE_ARRAYLIST_WSTR:
1591 case GATE_TYPE_ARRAYLIST_GUID:
1592 case GATE_TYPE_ARRAYLIST_DATE:
1593 case GATE_TYPE_ARRAYLIST_DAYTIME:
1594 case GATE_TYPE_ARRAYLIST_DATETIME:
1595 case GATE_TYPE_ARRAYLIST_TIME:
1596
1597 case GATE_TYPE_ARRAYLIST_STRING:
1598 case GATE_TYPE_ARRAYLIST_ARRAY:
1599 case GATE_TYPE_ARRAYLIST_BLOB:
1600
1601 case GATE_TYPE_ARRAYLIST_STRUCT:
1602 case GATE_TYPE_ARRAYLIST_OBJECT:
1603 case GATE_TYPE_ARRAYLIST_PROPERTY:
1604 break;
1605 }
1606
1607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (len_payload == 0)
1608 {
1609 /* error case */
1610 return 0;
1611 }
1612 else
1613 {
1614 23 return len_header + len_payload;
1615 }
1616 }
1617