| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, 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 | 144 | gate_value_t* gate_value_create(gate_type_id_t value_type, void const* src, gate_value_t* dst) | |
| 37 | { | ||
| 38 | 144 | gate_value_t* ret = NULL; | |
| 39 | 144 | gate_size_t len = gate_type_length(value_type); | |
| 40 | 144 | gate_array_t const* const ptr_array = (gate_array_t const*)src; | |
| 41 | 144 | gate_string_t const* const ptr_string = (gate_string_t const*)src; | |
| 42 | 144 | gate_blob_t const* const ptr_blob = (gate_blob_t const*)src; | |
| 43 | |||
| 44 |
3/4✓ Branch 0 taken 10 times.
✓ Branch 1 taken 134 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 134 times.
|
144 | if ((len != 0) && (dst != NULL)) |
| 45 | { | ||
| 46 | /* plain copy of bits */ | ||
| 47 |
1/2✓ Branch 0 taken 134 times.
✗ Branch 1 not taken.
|
134 | if (len > 0) |
| 48 | { | ||
| 49 | 134 | gate_mem_copy(&dst->content, src, len); | |
| 50 | } | ||
| 51 | 134 | dst->value_type = value_type; | |
| 52 | 134 | ret = dst; | |
| 53 |
4/5✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 121 times.
|
134 | switch (value_type) |
| 54 | { | ||
| 55 | 2 | case GATE_TYPE_ARRAY: | |
| 56 | { | ||
| 57 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (gate_array_duplicate(&dst->content.array_value, ptr_array) == NULL) |
| 58 | { | ||
| 59 | ✗ | ret = NULL; | |
| 60 | } | ||
| 61 | 2 | break; | |
| 62 | } | ||
| 63 | 4 | case GATE_TYPE_BLOB: | |
| 64 | { | ||
| 65 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (gate_blob_create_duplicate(&dst->content.blob_value, ptr_blob) == NULL) |
| 66 | { | ||
| 67 | ✗ | ret = NULL; | |
| 68 | } | ||
| 69 | 4 | break; | |
| 70 | } | ||
| 71 | 7 | case GATE_TYPE_STRING: | |
| 72 | { | ||
| 73 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | if (gate_string_clone(&dst->content.string_value, ptr_string) == NULL) |
| 74 | { | ||
| 75 | ✗ | ret = NULL; | |
| 76 | } | ||
| 77 | 7 | 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 | 144 | return ret; | |
| 90 | } | ||
| 91 | 38 | gate_value_t* gate_value_clone(gate_value_t const* src, gate_value_t* dst) | |
| 92 | { | ||
| 93 | 38 | gate_value_t* ret = NULL; | |
| 94 |
2/4✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
|
38 | if ((src != NULL) && (dst != NULL)) |
| 95 | { | ||
| 96 | 38 | ret = gate_value_create(src->value_type, &src->content.address_value, dst); | |
| 97 | } | ||
| 98 | 38 | return ret; | |
| 99 | } | ||
| 100 | 484 | void gate_value_release(gate_value_t* dst) | |
| 101 | { | ||
| 102 |
1/2✓ Branch 0 taken 484 times.
✗ Branch 1 not taken.
|
484 | if (dst != NULL) |
| 103 | { | ||
| 104 |
4/5✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 445 times.
|
484 | switch (dst->value_type) |
| 105 | { | ||
| 106 | 2 | case GATE_TYPE_ARRAY: | |
| 107 | { | ||
| 108 | 2 | gate_array_release(&dst->content.array_value); | |
| 109 | 2 | break; | |
| 110 | } | ||
| 111 | 20 | case GATE_TYPE_STRING: | |
| 112 | { | ||
| 113 | 20 | gate_string_release(&dst->content.string_value); | |
| 114 | 20 | break; | |
| 115 | } | ||
| 116 | 17 | case GATE_TYPE_BLOB: | |
| 117 | { | ||
| 118 | 17 | gate_blob_release(&dst->content.blob_value); | |
| 119 | 17 | 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 | 445 | default: | |
| 130 | { | ||
| 131 | 445 | break; | |
| 132 | } | ||
| 133 | } | ||
| 134 | 484 | gate_mem_clear(dst, sizeof(gate_value_t)); | |
| 135 | 484 | dst->value_type = GATE_TYPE_EMPTY; | |
| 136 | } | ||
| 137 | 484 | } | |
| 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 | 239 | gate_result_t gate_value_load_int64(gate_type_id_t value_type, void const* src, gate_int64_t* dst) | |
| 179 | { | ||
| 180 | 239 | gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY; | |
| 181 | 239 | gate_time_t tm = GATE_TIME_INIT; | |
| 182 | gate_result_t res; | ||
| 183 | |||
| 184 |
23/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 12 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 not taken.
|
239 | 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 | 12 | 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 | ✗ | return GATE_RESULT_NOTSUPPORTED; | |
| 287 | } | ||
| 288 | 7 | 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 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
7 | switch (value_type) |
| 293 | { | ||
| 294 | 3 | case GATE_TYPE_R32: *dst = (gate_real64_t) * ((gate_real32_t const*)src); return GATE_RESULT_OK; | |
| 295 | 3 | 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 | 33 | 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 4 times.
✓ Branch 1 taken 2 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 20 times.
|
33 | switch (value_type) |
| 405 | { | ||
| 406 | 4 | case GATE_TYPE_R32: | |
| 407 | case GATE_TYPE_R64: | ||
| 408 | { | ||
| 409 | 4 | ret = gate_value_load_real64(value_type, src, &tmpreal); | |
| 410 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (GATE_SUCCEEDED(ret)) |
| 411 | { | ||
| 412 | 4 | gate_strbuilder_create(&builder, 32); | |
| 413 | 4 | gate_strbuilder_append_real(&builder, tmpreal, 0, 6, 0); | |
| 414 | 4 | gate_strbuilder_to_string(&builder, dst); | |
| 415 | 4 | gate_strbuilder_release(&builder); | |
| 416 | } | ||
| 417 | 4 | 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 | 1 | case GATE_TYPE_STRING: | |
| 441 | { | ||
| 442 | 1 | return (NULL == gate_string_duplicate(dst, (gate_string_t const*)src)) | |
| 443 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | ? 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 | 20 | default: | |
| 501 | { | ||
| 502 | 20 | ret = gate_value_load_int64(value_type, src, &tmpint); | |
| 503 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (GATE_SUCCEEDED(ret)) |
| 504 | { | ||
| 505 | 20 | gate_strbuilder_create(&builder, 16); | |
| 506 | 20 | gate_strbuilder_append_int64(&builder, tmpint); | |
| 507 | 20 | gate_strbuilder_to_string(&builder, dst); | |
| 508 | 20 | gate_strbuilder_release(&builder); | |
| 509 | } | ||
| 510 | 20 | 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: return GATE_RESULT_NOTSUPPORTED; | |
| 898 | } | ||
| 899 | 30 | return GATE_RESULT_OK; | |
| 900 | } | ||
| 901 | |||
| 902 | #define BLOB_TO_NATIVE_TYPE(ptr_blob, native_type, ptr_target) \ | ||
| 903 | do { \ | ||
| 904 | gate_size_t blob_len = gate_blob_length(ptr_blob); \ | ||
| 905 | if(blob_len > sizeof(native_type)) blob_len = sizeof(native_type); \ | ||
| 906 | if(blob_len > 0) { \ | ||
| 907 | void const* blob_data = gate_blob_data(ptr_blob); \ | ||
| 908 | gate_mem_copy(ptr_target, blob_data, blob_len); \ | ||
| 909 | } \ | ||
| 910 | return GATE_RESULT_OK; \ | ||
| 911 | } while(0) | ||
| 912 | |||
| 913 | 23 | gate_result_t gate_value_save_blob(gate_blob_t const* src, gate_type_id_t dst_type, void* dst) | |
| 914 | { | ||
| 915 |
2/4✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
|
23 | if (!src || !dst) |
| 916 | { | ||
| 917 | ✗ | return GATE_RESULT_NULLPOINTER; | |
| 918 | } | ||
| 919 | |||
| 920 |
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) |
| 921 | { | ||
| 922 | 1 | case GATE_TYPE_BOOL: *((gate_bool_t*)dst) = gate_blob_length(src) != 0; return GATE_RESULT_OK; break; | |
| 923 |
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; |
| 924 |
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; |
| 925 |
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; |
| 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_I64: BLOB_TO_NATIVE_TYPE(src, gate_int64_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_UI8: BLOB_TO_NATIVE_TYPE(src, gate_uint8_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_UI16: BLOB_TO_NATIVE_TYPE(src, gate_uint16_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_UI32: BLOB_TO_NATIVE_TYPE(src, gate_uint32_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_UI64: BLOB_TO_NATIVE_TYPE(src, gate_uint64_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_R32: BLOB_TO_NATIVE_TYPE(src, gate_real32_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_R64: BLOB_TO_NATIVE_TYPE(src, gate_real64_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_ADDRESS: BLOB_TO_NATIVE_TYPE(src, gate_uintptr_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_DATAPTR: BLOB_TO_NATIVE_TYPE(src, gate_dataptr_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_FUNCPTR: BLOB_TO_NATIVE_TYPE(src, gate_funcptr_t, dst); break; |
| 936 | 1 | case GATE_TYPE_STRING: | |
| 937 | { | ||
| 938 | 1 | return (NULL == gate_string_create((gate_string_t*)dst, (char const*)gate_blob_data(src), gate_blob_length(src))) | |
| 939 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | ? GATE_RESULT_OUTOFMEMORY : GATE_RESULT_OK; |
| 940 | } | ||
| 941 | 1 | case GATE_TYPE_BLOB: | |
| 942 | { | ||
| 943 | 1 | return (NULL == gate_blob_create_clone((gate_blob_t*)dst, src)) | |
| 944 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | ? GATE_RESULT_OUTOFMEMORY : GATE_RESULT_OK; |
| 945 | } | ||
| 946 | 7 | default: | |
| 947 | { | ||
| 948 | gate_string_t str; | ||
| 949 | 7 | gate_string_create_static_len(&str, (char const*)gate_blob_data(src), gate_blob_length(src)); | |
| 950 | 7 | return gate_value_save_string(&str, dst_type, dst); | |
| 951 | } | ||
| 952 | } | ||
| 953 | return GATE_RESULT_FAILED; | ||
| 954 | } | ||
| 955 | |||
| 956 | |||
| 957 | |||
| 958 | ✗ | gate_result_t gate_value_copy_constructor(void* dest, void const* src) | |
| 959 | { | ||
| 960 | ✗ | if (NULL == gate_value_clone((gate_value_t const*)src, (gate_value_t*)dest)) | |
| 961 | { | ||
| 962 | ✗ | return GATE_RESULT_OUTOFMEMORY; | |
| 963 | } | ||
| 964 | else | ||
| 965 | { | ||
| 966 | ✗ | return GATE_RESULT_OK; | |
| 967 | } | ||
| 968 | } | ||
| 969 | ✗ | void gate_value_destructor(void* dest) | |
| 970 | { | ||
| 971 | ✗ | gate_value_release((gate_value_t*)dest); | |
| 972 | ✗ | } | |
| 973 | |||
| 974 | static gate_uint8_t const false_value = 0; | ||
| 975 | static gate_uint8_t const true_value = 1; | ||
| 976 | |||
| 977 | 3 | static gate_size_t gate_value_serialize_address(char* dest_buffer, gate_size_t dest_buffer_len, void* ptr) | |
| 978 | { | ||
| 979 | 3 | const gate_uint64_t u64 = (gate_uint64_t)(gate_uintptr_t)ptr; | |
| 980 | 3 | return gate_serialize_uint64_l(dest_buffer, dest_buffer_len, &u64); | |
| 981 | } | ||
| 982 | 3 | static gate_size_t gate_value_deserialize_address(char const* src_buffer, gate_size_t src_buffer_len, void** ptr) | |
| 983 | { | ||
| 984 | 3 | gate_uint64_t u64 = 0; | |
| 985 | 3 | gate_size_t ret = gate_deserialize_uint64_l(src_buffer, src_buffer_len, &u64); | |
| 986 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (ret > 0) |
| 987 | { | ||
| 988 | 3 | *ptr = (void*)(gate_uintptr_t)u64; | |
| 989 | } | ||
| 990 | 3 | return ret; | |
| 991 | } | ||
| 992 | |||
| 993 | 23 | gate_size_t gate_value_serialize(gate_value_t const* src, char* dest_buffer, gate_size_t dest_buffer_len) | |
| 994 | { | ||
| 995 | 23 | gate_size_t ret = 0; | |
| 996 | 23 | const gate_uint16_t ser_typeid = (gate_uint16_t)gate_value_type(src); | |
| 997 | |||
| 998 | 23 | gate_size_t len_payload = 0; | |
| 999 | 23 | gate_size_t len_header = gate_serialize_uint16_l(dest_buffer, dest_buffer_len, &ser_typeid); | |
| 1000 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (len_header == 0) |
| 1001 | { | ||
| 1002 | /* error case */ | ||
| 1003 | ✗ | return 0; | |
| 1004 | } | ||
| 1005 | |||
| 1006 | 23 | dest_buffer += len_header; | |
| 1007 | 23 | dest_buffer_len -= len_header; | |
| 1008 | |||
| 1009 |
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) |
| 1010 | { | ||
| 1011 | ✗ | case GATE_TYPE_VOID: { len_payload = gate_serialize_uint8_l(dest_buffer, dest_buffer_len, &false_value); break; } | |
| 1012 |
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; } |
| 1013 | 1 | case GATE_TYPE_I8: { len_payload = gate_serialize_int8_l(dest_buffer, dest_buffer_len, &src->content.i8_value); break; } | |
| 1014 | 1 | case GATE_TYPE_UI8: { len_payload = gate_serialize_uint8_l(dest_buffer, dest_buffer_len, &src->content.ui8_value); break; } | |
| 1015 | 1 | case GATE_TYPE_I16: { len_payload = gate_serialize_int16_l(dest_buffer, dest_buffer_len, &src->content.i16_value); break; } | |
| 1016 | 1 | case GATE_TYPE_UI16: { len_payload = gate_serialize_uint16_l(dest_buffer, dest_buffer_len, &src->content.ui16_value); break; } | |
| 1017 | 1 | case GATE_TYPE_I32: { len_payload = gate_serialize_int32_l(dest_buffer, dest_buffer_len, &src->content.i32_value); break; } | |
| 1018 | 1 | case GATE_TYPE_UI32: { len_payload = gate_serialize_uint32_l(dest_buffer, dest_buffer_len, &src->content.ui32_value); break; } | |
| 1019 | 1 | case GATE_TYPE_I64: { len_payload = gate_serialize_int64_l(dest_buffer, dest_buffer_len, &src->content.i64_value); break; } | |
| 1020 | 1 | case GATE_TYPE_UI64: { len_payload = gate_serialize_uint64_l(dest_buffer, dest_buffer_len, &src->content.ui64_value); break; } | |
| 1021 | 1 | case GATE_TYPE_R32: { len_payload = gate_serialize_real32_l(dest_buffer, dest_buffer_len, &src->content.r32_value); break; } | |
| 1022 | 1 | case GATE_TYPE_R64: { len_payload = gate_serialize_real64_l(dest_buffer, dest_buffer_len, &src->content.r64_value); break; } | |
| 1023 | 1 | case GATE_TYPE_ADDRESS: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.address_value); break; } | |
| 1024 | 1 | case GATE_TYPE_DATAPTR: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.ptr_value); break; } | |
| 1025 | 1 | case GATE_TYPE_FUNCPTR: { len_payload = gate_value_serialize_address(dest_buffer, dest_buffer_len, (void*)src->content.address_value); break; } | |
| 1026 | 1 | case GATE_TYPE_CSTR: | |
| 1027 | { | ||
| 1028 | 1 | gate_size_t len_str = gate_str_length(src->content.cstring_value); | |
| 1029 | 1 | gate_uint32_t len_bytes = (gate_uint32_t)(len_str + 1); | |
| 1030 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= (len_bytes + 4)) |
| 1031 | { | ||
| 1032 | 1 | gate_serialize_uint32_l(dest_buffer, 4, &len_bytes); | |
| 1033 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_str > 0) |
| 1034 | { | ||
| 1035 | 1 | gate_mem_copy(&dest_buffer[4], src->content.cstring_value, len_str); | |
| 1036 | } | ||
| 1037 | 1 | dest_buffer[4 + len_str] = 0; | |
| 1038 | 1 | len_payload = len_bytes + 4; | |
| 1039 | } | ||
| 1040 | 1 | break; | |
| 1041 | } | ||
| 1042 | 1 | case GATE_TYPE_WSTR: | |
| 1043 | { | ||
| 1044 | 1 | gate_size_t len_str = gate_wstr_length(src->content.wstring_value); | |
| 1045 | 1 | gate_uint32_t len_bytes = (gate_uint32_t)((len_str + 1) * sizeof(wchar_t)); | |
| 1046 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= (len_bytes + 4)) |
| 1047 | { | ||
| 1048 | 1 | gate_serialize_uint32_l(dest_buffer, 4, &len_bytes); | |
| 1049 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_str > 0) |
| 1050 | { | ||
| 1051 | 1 | gate_mem_copy(&dest_buffer[4], src->content.wstring_value, len_str * sizeof(wchar_t)); | |
| 1052 | } | ||
| 1053 | 1 | gate_mem_clear(&dest_buffer[4 + len_str * sizeof(wchar_t)], sizeof(wchar_t)); | |
| 1054 | 1 | len_payload = len_bytes + 4; | |
| 1055 | } | ||
| 1056 | 1 | break; | |
| 1057 | } | ||
| 1058 | 1 | case GATE_TYPE_GUID: | |
| 1059 | { | ||
| 1060 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= 16) |
| 1061 | { | ||
| 1062 | 1 | gate_serialize_uint32_l(&dest_buffer[0], 4, &src->content.guid_value.item1); | |
| 1063 | 1 | gate_serialize_uint16_l(&dest_buffer[4], 2, &src->content.guid_value.item2); | |
| 1064 | 1 | gate_serialize_uint16_l(&dest_buffer[6], 2, &src->content.guid_value.item3); | |
| 1065 | 1 | gate_mem_copy(&dest_buffer[8], src->content.guid_value.item4, 8); | |
| 1066 | 1 | len_payload = 16; | |
| 1067 | } | ||
| 1068 | 1 | break; | |
| 1069 | } | ||
| 1070 | 1 | case GATE_TYPE_DATE: | |
| 1071 | { | ||
| 1072 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= 4) |
| 1073 | { | ||
| 1074 | 1 | gate_serialize_uint16_l(&dest_buffer[0], 2, &src->content.date_value.year); | |
| 1075 | 1 | gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.date_value.month); | |
| 1076 | 1 | gate_serialize_uint8_l(&dest_buffer[3], 1, &src->content.date_value.day); | |
| 1077 | 1 | len_payload = 4; | |
| 1078 | } | ||
| 1079 | 1 | break; | |
| 1080 | } | ||
| 1081 | 1 | case GATE_TYPE_DAYTIME: | |
| 1082 | { | ||
| 1083 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= 6) |
| 1084 | { | ||
| 1085 | char buf[4]; | ||
| 1086 | 1 | const gate_uint32_t micro = src->content.daytime_value.microsecond % 1000000; | |
| 1087 | 1 | gate_serialize_uint8_l(&dest_buffer[0], 1, &src->content.daytime_value.hour); | |
| 1088 | 1 | gate_serialize_uint8_l(&dest_buffer[1], 1, &src->content.daytime_value.minute); | |
| 1089 | 1 | gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.daytime_value.second); | |
| 1090 | 1 | gate_serialize_uint32_l(&buf[0], 4, µ); | |
| 1091 | 1 | gate_mem_copy(&dest_buffer[3], &buf[0], 3); | |
| 1092 | 1 | len_payload = 6; | |
| 1093 | } | ||
| 1094 | 1 | break; | |
| 1095 | } | ||
| 1096 | 1 | case GATE_TYPE_DATETIME: | |
| 1097 | { | ||
| 1098 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= 10) |
| 1099 | { | ||
| 1100 | char buf[4]; | ||
| 1101 | 1 | const gate_uint32_t micro = src->content.daytime_value.microsecond % 1000000; | |
| 1102 | 1 | gate_serialize_uint16_l(&dest_buffer[0], 2, &src->content.date_value.year); | |
| 1103 | 1 | gate_serialize_uint8_l(&dest_buffer[2], 1, &src->content.date_value.month); | |
| 1104 | 1 | gate_serialize_uint8_l(&dest_buffer[3], 1, &src->content.date_value.day); | |
| 1105 | 1 | gate_serialize_uint8_l(&dest_buffer[4], 1, &src->content.daytime_value.hour); | |
| 1106 | 1 | gate_serialize_uint8_l(&dest_buffer[5], 1, &src->content.daytime_value.minute); | |
| 1107 | 1 | gate_serialize_uint8_l(&dest_buffer[6], 1, &src->content.daytime_value.second); | |
| 1108 | 1 | gate_serialize_uint32_l(&buf[0], 4, µ); | |
| 1109 | 1 | gate_mem_copy(&dest_buffer[7], &buf[0], 3); | |
| 1110 | 1 | len_payload = 10; | |
| 1111 | } | ||
| 1112 | 1 | break; | |
| 1113 | } | ||
| 1114 | 1 | case GATE_TYPE_TIME: | |
| 1115 | { | ||
| 1116 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= 10) |
| 1117 | { | ||
| 1118 | 1 | const gate_int64_t ts = src->content.time_value.timestamp; | |
| 1119 | 1 | const gate_int16_t b = src->content.time_value.bias; | |
| 1120 | 1 | gate_serialize_int64_l(&dest_buffer[0], 8, &ts); | |
| 1121 | 1 | gate_serialize_int16_l(&dest_buffer[8], 2, &b); | |
| 1122 | 1 | len_payload = 10; | |
| 1123 | } | ||
| 1124 | 1 | break; | |
| 1125 | } | ||
| 1126 | 1 | case GATE_TYPE_STRING: | |
| 1127 | { | ||
| 1128 | 1 | const gate_uint32_t str_len = (gate_uint32_t)gate_string_length(&src->content.string_value); | |
| 1129 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= str_len + 4) |
| 1130 | { | ||
| 1131 | 1 | gate_serialize_uint32_l(&dest_buffer[0], 4, &str_len); | |
| 1132 | 1 | gate_mem_copy(&dest_buffer[4], gate_string_ptr(&src->content.string_value, 0), str_len); | |
| 1133 | 1 | len_payload = str_len + 4; | |
| 1134 | } | ||
| 1135 | 1 | break; | |
| 1136 | } | ||
| 1137 | ✗ | case GATE_TYPE_ARRAY: | |
| 1138 | { | ||
| 1139 | /* type-less arrays are not supported in serialization */ | ||
| 1140 | ✗ | break; | |
| 1141 | } | ||
| 1142 | 1 | case GATE_TYPE_BLOB: | |
| 1143 | { | ||
| 1144 | 1 | const gate_uint32_t blob_len = (gate_uint32_t)gate_blob_length(&src->content.blob_value); | |
| 1145 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (dest_buffer_len >= blob_len + 4) |
| 1146 | { | ||
| 1147 | 1 | gate_serialize_uint32_l(&dest_buffer[0], 4, &blob_len); | |
| 1148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (blob_len > 0) |
| 1149 | { | ||
| 1150 | ✗ | gate_mem_copy(&dest_buffer[4], gate_blob_data(&src->content.blob_value), blob_len); | |
| 1151 | } | ||
| 1152 | 1 | len_payload = blob_len + 4; | |
| 1153 | } | ||
| 1154 | 1 | break; | |
| 1155 | } | ||
| 1156 | ✗ | case GATE_TYPE_STRUCT: | |
| 1157 | case GATE_TYPE_OBJECT: | ||
| 1158 | case GATE_TYPE_PROPERTY: | ||
| 1159 | |||
| 1160 | case GATE_TYPE_ARRAYLIST: | ||
| 1161 | case GATE_TYPE_ARRAYLIST_BOOL: | ||
| 1162 | case GATE_TYPE_ARRAYLIST_I8: | ||
| 1163 | case GATE_TYPE_ARRAYLIST_UI8: | ||
| 1164 | case GATE_TYPE_ARRAYLIST_I16: | ||
| 1165 | case GATE_TYPE_ARRAYLIST_UI16: | ||
| 1166 | case GATE_TYPE_ARRAYLIST_I32: | ||
| 1167 | case GATE_TYPE_ARRAYLIST_UI32: | ||
| 1168 | case GATE_TYPE_ARRAYLIST_I64: | ||
| 1169 | case GATE_TYPE_ARRAYLIST_UI64: | ||
| 1170 | case GATE_TYPE_ARRAYLIST_R32: | ||
| 1171 | case GATE_TYPE_ARRAYLIST_R64: | ||
| 1172 | case GATE_TYPE_ARRAYLIST_ADDRESS: | ||
| 1173 | |||
| 1174 | case GATE_TYPE_ARRAYLIST_DATAPTR: | ||
| 1175 | case GATE_TYPE_ARRAYLIST_FUNCPTR: | ||
| 1176 | case GATE_TYPE_ARRAYLIST_CSTR: | ||
| 1177 | case GATE_TYPE_ARRAYLIST_WSTR: | ||
| 1178 | case GATE_TYPE_ARRAYLIST_GUID: | ||
| 1179 | case GATE_TYPE_ARRAYLIST_DATE: | ||
| 1180 | case GATE_TYPE_ARRAYLIST_DAYTIME: | ||
| 1181 | case GATE_TYPE_ARRAYLIST_DATETIME: | ||
| 1182 | case GATE_TYPE_ARRAYLIST_TIME: | ||
| 1183 | |||
| 1184 | case GATE_TYPE_ARRAYLIST_STRING: | ||
| 1185 | case GATE_TYPE_ARRAYLIST_ARRAY: | ||
| 1186 | |||
| 1187 | case GATE_TYPE_ARRAYLIST_STRUCT: | ||
| 1188 | case GATE_TYPE_ARRAYLIST_OBJECT: | ||
| 1189 | case GATE_TYPE_ARRAYLIST_PROPERTY: | ||
| 1190 | ✗ | break; | |
| 1191 | } | ||
| 1192 | |||
| 1193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (len_payload == 0) |
| 1194 | { | ||
| 1195 | /* error case */ | ||
| 1196 | ✗ | return 0; | |
| 1197 | } | ||
| 1198 | else | ||
| 1199 | { | ||
| 1200 | /* success case */ | ||
| 1201 | 23 | return len_header + len_payload; | |
| 1202 | } | ||
| 1203 | return ret; | ||
| 1204 | } | ||
| 1205 | |||
| 1206 | 23 | gate_size_t gate_value_deserialize(char const* src_buffer, gate_size_t src_buffer_len, gate_value_t* dst) | |
| 1207 | { | ||
| 1208 | 23 | gate_uint16_t ser_type = 0; | |
| 1209 | 23 | gate_size_t len_header = gate_deserialize_uint16_l(src_buffer, src_buffer_len, &ser_type); | |
| 1210 | 23 | gate_size_t len_payload = 0; | |
| 1211 | |||
| 1212 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (len_header == 0) |
| 1213 | { | ||
| 1214 | /* error case */ | ||
| 1215 | ✗ | return 0; | |
| 1216 | } | ||
| 1217 | |||
| 1218 | 23 | src_buffer += len_header; | |
| 1219 | 23 | src_buffer_len -= len_header; | |
| 1220 | |||
| 1221 |
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) |
| 1222 | { | ||
| 1223 | ✗ | case GATE_TYPE_VOID: | |
| 1224 | { | ||
| 1225 | ✗ | gate_uint8_t v = 0; | |
| 1226 | ✗ | len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v); | |
| 1227 | ✗ | if (len_payload > 0) | |
| 1228 | { | ||
| 1229 | ✗ | gate_mem_clear(dst, sizeof(gate_value_t)); | |
| 1230 | } | ||
| 1231 | ✗ | break; | |
| 1232 | } | ||
| 1233 | 1 | case GATE_TYPE_BOOL: | |
| 1234 | { | ||
| 1235 | 1 | gate_uint8_t v = 0; | |
| 1236 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | v = (v != 0) ? true_value : false_value; |
| 1237 | 1 | len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v); | |
| 1238 |
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))) |
| 1239 | { | ||
| 1240 | ✗ | len_payload = 0; | |
| 1241 | } | ||
| 1242 | 1 | break; | |
| 1243 | } | ||
| 1244 | 1 | case GATE_TYPE_I8: | |
| 1245 | { | ||
| 1246 | 1 | gate_int8_t v = 0; | |
| 1247 | 1 | len_payload = gate_deserialize_int8_l(src_buffer, src_buffer_len, &v); | |
| 1248 |
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))) |
| 1249 | { | ||
| 1250 | ✗ | len_payload = 0; | |
| 1251 | } | ||
| 1252 | 1 | break; | |
| 1253 | } | ||
| 1254 | 1 | case GATE_TYPE_UI8: | |
| 1255 | { | ||
| 1256 | 1 | gate_uint8_t v = 0; | |
| 1257 | 1 | len_payload = gate_deserialize_uint8_l(src_buffer, src_buffer_len, &v); | |
| 1258 |
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))) |
| 1259 | { | ||
| 1260 | ✗ | len_payload = 0; | |
| 1261 | } | ||
| 1262 | 1 | break; | |
| 1263 | } | ||
| 1264 | 1 | case GATE_TYPE_I16: | |
| 1265 | { | ||
| 1266 | 1 | gate_int16_t v = 0; | |
| 1267 | 1 | len_payload = gate_deserialize_int16_l(src_buffer, src_buffer_len, &v); | |
| 1268 |
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))) |
| 1269 | { | ||
| 1270 | ✗ | len_payload = 0; | |
| 1271 | } | ||
| 1272 | 1 | break; | |
| 1273 | } | ||
| 1274 | 1 | case GATE_TYPE_UI16: | |
| 1275 | { | ||
| 1276 | 1 | gate_uint16_t v = 0; | |
| 1277 | 1 | len_payload = gate_deserialize_uint16_l(src_buffer, src_buffer_len, &v); | |
| 1278 |
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))) |
| 1279 | { | ||
| 1280 | ✗ | len_payload = 0; | |
| 1281 | } | ||
| 1282 | 1 | break; | |
| 1283 | } | ||
| 1284 | 1 | case GATE_TYPE_I32: | |
| 1285 | { | ||
| 1286 | 1 | gate_int32_t v = 0; | |
| 1287 | 1 | len_payload = gate_deserialize_int32_l(src_buffer, src_buffer_len, &v); | |
| 1288 |
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))) |
| 1289 | { | ||
| 1290 | ✗ | len_payload = 0; | |
| 1291 | } | ||
| 1292 | 1 | break; | |
| 1293 | } | ||
| 1294 | 1 | case GATE_TYPE_UI32: | |
| 1295 | { | ||
| 1296 | 1 | gate_uint32_t v = 0; | |
| 1297 | 1 | len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &v); | |
| 1298 |
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))) |
| 1299 | { | ||
| 1300 | ✗ | len_payload = 0; | |
| 1301 | } | ||
| 1302 | 1 | break; | |
| 1303 | } | ||
| 1304 | 1 | case GATE_TYPE_I64: | |
| 1305 | { | ||
| 1306 | 1 | gate_int64_t v = 0; | |
| 1307 | 1 | len_payload = gate_deserialize_int64_l(src_buffer, src_buffer_len, &v); | |
| 1308 |
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))) |
| 1309 | { | ||
| 1310 | ✗ | len_payload = 0; | |
| 1311 | } | ||
| 1312 | 1 | break; | |
| 1313 | } | ||
| 1314 | 1 | case GATE_TYPE_UI64: | |
| 1315 | { | ||
| 1316 | 1 | gate_uint64_t v = 0; | |
| 1317 | 1 | len_payload = gate_deserialize_uint64_l(src_buffer, src_buffer_len, &v); | |
| 1318 |
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))) |
| 1319 | { | ||
| 1320 | ✗ | len_payload = 0; | |
| 1321 | } | ||
| 1322 | 1 | break; | |
| 1323 | } | ||
| 1324 | 1 | case GATE_TYPE_R32: | |
| 1325 | { | ||
| 1326 | 1 | gate_real32_t v = 0.0f; | |
| 1327 | 1 | len_payload = gate_deserialize_real32_l(src_buffer, src_buffer_len, &v); | |
| 1328 |
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))) |
| 1329 | { | ||
| 1330 | ✗ | len_payload = 0; | |
| 1331 | } | ||
| 1332 | 1 | break; | |
| 1333 | } | ||
| 1334 | 1 | case GATE_TYPE_R64: | |
| 1335 | { | ||
| 1336 | 1 | gate_real64_t v = 0.0; | |
| 1337 | 1 | len_payload = gate_deserialize_real64_l(src_buffer, src_buffer_len, &v); | |
| 1338 |
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))) |
| 1339 | { | ||
| 1340 | ✗ | len_payload = 0; | |
| 1341 | } | ||
| 1342 | 1 | break; | |
| 1343 | } | ||
| 1344 | 1 | case GATE_TYPE_ADDRESS: | |
| 1345 | { | ||
| 1346 | 1 | void* ptr = NULL; | |
| 1347 | 1 | len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr); | |
| 1348 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_payload > 0) |
| 1349 | { | ||
| 1350 | 1 | const gate_uintptr_t v = (gate_uintptr_t)ptr; | |
| 1351 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_value_create(ser_type, &v, dst)) |
| 1352 | { | ||
| 1353 | ✗ | len_payload = 0; | |
| 1354 | } | ||
| 1355 | } | ||
| 1356 | 1 | break; | |
| 1357 | } | ||
| 1358 | 1 | case GATE_TYPE_DATAPTR: | |
| 1359 | { | ||
| 1360 | 1 | void* ptr = NULL; | |
| 1361 | 1 | len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr); | |
| 1362 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_payload > 0) |
| 1363 | { | ||
| 1364 | 1 | const gate_dataptr_t v = (gate_dataptr_t)ptr; | |
| 1365 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_value_create(ser_type, &v, dst)) |
| 1366 | { | ||
| 1367 | ✗ | len_payload = 0; | |
| 1368 | } | ||
| 1369 | } | ||
| 1370 | 1 | break; | |
| 1371 | } | ||
| 1372 | 1 | case GATE_TYPE_FUNCPTR: | |
| 1373 | { | ||
| 1374 | 1 | void* ptr = NULL; | |
| 1375 | 1 | len_payload = gate_value_deserialize_address(src_buffer, src_buffer_len, &ptr); | |
| 1376 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_payload > 0) |
| 1377 | { | ||
| 1378 | 1 | const gate_funcptr_t v = (gate_funcptr_t)ptr; | |
| 1379 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_value_create(ser_type, &v, dst)) |
| 1380 | { | ||
| 1381 | ✗ | len_payload = 0; | |
| 1382 | } | ||
| 1383 | } | ||
| 1384 | 1 | break; | |
| 1385 | } | ||
| 1386 | 1 | case GATE_TYPE_CSTR: | |
| 1387 | { | ||
| 1388 | 1 | gate_uint32_t len_str = 0; | |
| 1389 | 1 | len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_str); | |
| 1390 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_payload > 0) |
| 1391 | { | ||
| 1392 | 1 | len_payload = 0; /* reset to error case */ | |
| 1393 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= len_str + 4) |
| 1394 | { | ||
| 1395 | 1 | gate_cstr_t const str = (gate_cstr_t)(src_buffer + 4); | |
| 1396 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &str, dst)) |
| 1397 | { | ||
| 1398 | /* succes case */ | ||
| 1399 | 1 | len_payload = len_str + 4; | |
| 1400 | } | ||
| 1401 | } | ||
| 1402 | } | ||
| 1403 | 1 | break; | |
| 1404 | } | ||
| 1405 | 1 | case GATE_TYPE_WSTR: | |
| 1406 | { | ||
| 1407 | 1 | gate_uint32_t len_str = 0; | |
| 1408 | 1 | len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_str); | |
| 1409 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_payload > 0) |
| 1410 | { | ||
| 1411 | 1 | len_payload = 0; /* reset to error case */ | |
| 1412 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= len_str + 4) |
| 1413 | { | ||
| 1414 | 1 | gate_wstr_t const str = (gate_wstr_t)(src_buffer + 4); | |
| 1415 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &str, dst)) |
| 1416 | { | ||
| 1417 | /* success case */ | ||
| 1418 | 1 | len_payload = len_str + 4; | |
| 1419 | } | ||
| 1420 | } | ||
| 1421 | } | ||
| 1422 | 1 | break; | |
| 1423 | } | ||
| 1424 | 1 | case GATE_TYPE_GUID: | |
| 1425 | { | ||
| 1426 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= 16) |
| 1427 | { | ||
| 1428 | 1 | gate_guid_t v = GATE_INIT_EMPTY; | |
| 1429 | 1 | gate_deserialize_uint32_l(&src_buffer[0], 4, &v.item1); | |
| 1430 | 1 | gate_deserialize_uint16_l(&src_buffer[4], 2, &v.item2); | |
| 1431 | 1 | gate_deserialize_uint16_l(&src_buffer[6], 2, &v.item3); | |
| 1432 | 1 | gate_mem_copy(&v.item4[0], &src_buffer[8], 8); | |
| 1433 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &v, dst)) |
| 1434 | { | ||
| 1435 | /* success case */ | ||
| 1436 | 1 | len_payload = 16; | |
| 1437 | } | ||
| 1438 | } | ||
| 1439 | 1 | break; | |
| 1440 | } | ||
| 1441 | 1 | case GATE_TYPE_DATE: | |
| 1442 | { | ||
| 1443 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= 4) |
| 1444 | { | ||
| 1445 | 1 | gate_date_t dt = GATE_DATE_INIT_EMPTY; | |
| 1446 | 1 | gate_deserialize_uint16_l(&src_buffer[0], 2, &dt.year); | |
| 1447 | 1 | gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.month); | |
| 1448 | 1 | gate_deserialize_uint8_l(&src_buffer[3], 1, &dt.day); | |
| 1449 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &dt, dst)) |
| 1450 | { | ||
| 1451 | /* success case */ | ||
| 1452 | 1 | len_payload = 4; | |
| 1453 | } | ||
| 1454 | } | ||
| 1455 | 1 | break; | |
| 1456 | } | ||
| 1457 | 1 | case GATE_TYPE_DAYTIME: | |
| 1458 | { | ||
| 1459 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= 6) |
| 1460 | { | ||
| 1461 | 1 | gate_daytime_t dt = GATE_DAYTIME_INIT_EMPTY; | |
| 1462 | char buf[4]; | ||
| 1463 | 1 | gate_deserialize_uint8_l(&src_buffer[0], 1, &dt.hour); | |
| 1464 | 1 | gate_deserialize_uint8_l(&src_buffer[1], 1, &dt.minute); | |
| 1465 | 1 | gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.second); | |
| 1466 | 1 | gate_mem_copy(buf, &src_buffer[3], 3); | |
| 1467 | 1 | buf[3] = 0; | |
| 1468 | 1 | gate_deserialize_uint32_l(buf, 4, &dt.microsecond); | |
| 1469 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &dt, dst)) |
| 1470 | { | ||
| 1471 | /* success case */ | ||
| 1472 | 1 | len_payload = 6; | |
| 1473 | } | ||
| 1474 | } | ||
| 1475 | 1 | break; | |
| 1476 | } | ||
| 1477 | 1 | case GATE_TYPE_DATETIME: | |
| 1478 | { | ||
| 1479 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= 10) |
| 1480 | { | ||
| 1481 | 1 | gate_datetime_t dt = GATE_DATETIME_INIT_EMPTY; | |
| 1482 | char buf[4]; | ||
| 1483 | 1 | gate_deserialize_uint16_l(&src_buffer[0], 2, &dt.date.year); | |
| 1484 | 1 | gate_deserialize_uint8_l(&src_buffer[2], 1, &dt.date.month); | |
| 1485 | 1 | gate_deserialize_uint8_l(&src_buffer[3], 1, &dt.date.day); | |
| 1486 | 1 | gate_deserialize_uint8_l(&src_buffer[4], 1, &dt.time.hour); | |
| 1487 | 1 | gate_deserialize_uint8_l(&src_buffer[5], 1, &dt.time.minute); | |
| 1488 | 1 | gate_deserialize_uint8_l(&src_buffer[6], 1, &dt.time.second); | |
| 1489 | 1 | gate_mem_copy(buf, &src_buffer[7], 3); | |
| 1490 | 1 | buf[3] = 0; | |
| 1491 | 1 | gate_deserialize_uint32_l(buf, 4, &dt.time.microsecond); | |
| 1492 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &dt, dst)) |
| 1493 | { | ||
| 1494 | /* success case */ | ||
| 1495 | 1 | len_payload = 10; | |
| 1496 | } | ||
| 1497 | } | ||
| 1498 | 1 | break; | |
| 1499 | } | ||
| 1500 | 1 | case GATE_TYPE_TIME: | |
| 1501 | { | ||
| 1502 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= 10) |
| 1503 | { | ||
| 1504 | 1 | gate_time_t tm = GATE_TIME_INIT; | |
| 1505 | 1 | gate_deserialize_int64_l(&src_buffer[0], 8, &tm.timestamp); | |
| 1506 | 1 | gate_deserialize_int16_l(&src_buffer[8], 2, &tm.bias); | |
| 1507 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &tm, dst)) |
| 1508 | { | ||
| 1509 | /* success case */ | ||
| 1510 | 1 | len_payload = 10; | |
| 1511 | } | ||
| 1512 | } | ||
| 1513 | 1 | break; | |
| 1514 | } | ||
| 1515 | 1 | case GATE_TYPE_STRING: | |
| 1516 | { | ||
| 1517 | 1 | gate_uint32_t len_chars = 0; | |
| 1518 | 1 | len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_chars); | |
| 1519 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_payload != 0) |
| 1520 | { | ||
| 1521 | 1 | len_payload = 0; | |
| 1522 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= len_chars + 4) |
| 1523 | { | ||
| 1524 | 1 | gate_string_t text = GATE_STRING_INIT_EMPTY; | |
| 1525 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_string_create(&text, &src_buffer[4], len_chars)) |
| 1526 | { | ||
| 1527 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &text, dst)) |
| 1528 | { | ||
| 1529 | /* success case */ | ||
| 1530 | 1 | len_payload = len_chars + 4; | |
| 1531 | } | ||
| 1532 | 1 | gate_string_release(&text); | |
| 1533 | } | ||
| 1534 | } | ||
| 1535 | } | ||
| 1536 | 1 | break; | |
| 1537 | } | ||
| 1538 | ✗ | case GATE_TYPE_ARRAY: | |
| 1539 | { | ||
| 1540 | ✗ | break; | |
| 1541 | } | ||
| 1542 | 1 | case GATE_TYPE_BLOB: | |
| 1543 | { | ||
| 1544 | 1 | gate_uint32_t len_bytes = 0; | |
| 1545 | 1 | len_payload = gate_deserialize_uint32_l(src_buffer, src_buffer_len, &len_bytes); | |
| 1546 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (len_payload != 0) |
| 1547 | { | ||
| 1548 | 1 | len_payload = 0; | |
| 1549 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (src_buffer_len >= len_bytes + 4) |
| 1550 | { | ||
| 1551 | 1 | gate_blob_t blob = GATE_INIT_EMPTY; | |
| 1552 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_blob_create(&blob, &src_buffer[4], len_bytes)) |
| 1553 | { | ||
| 1554 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (NULL != gate_value_create(ser_type, &blob, dst)) |
| 1555 | { | ||
| 1556 | /* success case */ | ||
| 1557 | 1 | len_payload = len_bytes + 4; | |
| 1558 | } | ||
| 1559 | 1 | gate_blob_release(&blob); | |
| 1560 | } | ||
| 1561 | } | ||
| 1562 | } | ||
| 1563 | 1 | break; | |
| 1564 | } | ||
| 1565 | ✗ | case GATE_TYPE_STRUCT: | |
| 1566 | case GATE_TYPE_OBJECT: | ||
| 1567 | case GATE_TYPE_PROPERTY: | ||
| 1568 | |||
| 1569 | case GATE_TYPE_ARRAYLIST: | ||
| 1570 | case GATE_TYPE_ARRAYLIST_BOOL: | ||
| 1571 | case GATE_TYPE_ARRAYLIST_I8: | ||
| 1572 | case GATE_TYPE_ARRAYLIST_UI8: | ||
| 1573 | case GATE_TYPE_ARRAYLIST_I16: | ||
| 1574 | case GATE_TYPE_ARRAYLIST_UI16: | ||
| 1575 | case GATE_TYPE_ARRAYLIST_I32: | ||
| 1576 | case GATE_TYPE_ARRAYLIST_UI32: | ||
| 1577 | case GATE_TYPE_ARRAYLIST_I64: | ||
| 1578 | case GATE_TYPE_ARRAYLIST_UI64: | ||
| 1579 | case GATE_TYPE_ARRAYLIST_R32: | ||
| 1580 | case GATE_TYPE_ARRAYLIST_R64: | ||
| 1581 | case GATE_TYPE_ARRAYLIST_ADDRESS: | ||
| 1582 | |||
| 1583 | case GATE_TYPE_ARRAYLIST_DATAPTR: | ||
| 1584 | case GATE_TYPE_ARRAYLIST_FUNCPTR: | ||
| 1585 | case GATE_TYPE_ARRAYLIST_CSTR: | ||
| 1586 | case GATE_TYPE_ARRAYLIST_WSTR: | ||
| 1587 | case GATE_TYPE_ARRAYLIST_GUID: | ||
| 1588 | case GATE_TYPE_ARRAYLIST_DATE: | ||
| 1589 | case GATE_TYPE_ARRAYLIST_DAYTIME: | ||
| 1590 | case GATE_TYPE_ARRAYLIST_DATETIME: | ||
| 1591 | case GATE_TYPE_ARRAYLIST_TIME: | ||
| 1592 | |||
| 1593 | case GATE_TYPE_ARRAYLIST_STRING: | ||
| 1594 | case GATE_TYPE_ARRAYLIST_ARRAY: | ||
| 1595 | case GATE_TYPE_ARRAYLIST_BLOB: | ||
| 1596 | |||
| 1597 | case GATE_TYPE_ARRAYLIST_STRUCT: | ||
| 1598 | case GATE_TYPE_ARRAYLIST_OBJECT: | ||
| 1599 | case GATE_TYPE_ARRAYLIST_PROPERTY: | ||
| 1600 | ✗ | break; | |
| 1601 | } | ||
| 1602 | |||
| 1603 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (len_payload == 0) |
| 1604 | { | ||
| 1605 | /* error case */ | ||
| 1606 | ✗ | return 0; | |
| 1607 | } | ||
| 1608 | else | ||
| 1609 | { | ||
| 1610 | 23 | return len_header + len_payload; | |
| 1611 | } | ||
| 1612 | } | ||
| 1613 |