constr_CHOICE_rfill.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
8 
11  const asn_encoding_constraints_t *constr,
12  size_t max_length) {
13  const asn_CHOICE_specifics_t *specs =
14  (const asn_CHOICE_specifics_t *)td->specifics;
16  asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
17  asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
18  const asn_TYPE_member_t *elm;
19  unsigned present;
20  void *memb_ptr; /* Pointer to the member */
21  void **memb_ptr2; /* Pointer to that pointer */
22  void *st = *sptr;
23 
24  if(max_length == 0) return result_skipped;
25 
26  (void)constr;
27 
28  if(st == NULL) {
29  st = CALLOC(1, specs->struct_size);
30  if(st == NULL) {
31  return result_failed;
32  }
33  }
34 
35  present = asn_random_between(1, td->elements_count);
36  elm = &td->elements[present - 1];
37 
38  if(elm->flags & ATF_POINTER) {
39  /* Member is a pointer to another structure */
40  memb_ptr2 = (void **)((char *)st + elm->memb_offset);
41  } else {
42  memb_ptr = (char *)st + elm->memb_offset;
43  memb_ptr2 = &memb_ptr;
44  }
45 
46  res = elm->type->op->random_fill(elm->type, memb_ptr2,
47  &elm->encoding_constraints, max_length);
48  _set_present_idx(st, specs->pres_offset, specs->pres_size, present);
49  if(res.code == ARFILL_OK) {
50  *sptr = st;
51  } else {
52  if(st == *sptr) {
53  ASN_STRUCT_RESET(*td, st);
54  } else {
55  ASN_STRUCT_FREE(*td, st);
56  }
57  }
58 
59  return res;
60 }
ASN_STRUCT_FREE
#define ASN_STRUCT_FREE(asn_DEF, ptr)
Definition: constr_TYPE.h:102
asn_TYPE_member_s::memb_offset
unsigned memb_offset
Definition: constr_TYPE.h:275
CALLOC
#define CALLOC(nmemb, size)
Definition: asn_internal.h:37
asn_CHOICE_specifics_s
Definition: constr_CHOICE.h:14
ASN_STRUCT_RESET
#define ASN_STRUCT_RESET(asn_DEF, ptr)
Definition: constr_TYPE.h:112
CHOICE_random_fill
asn_random_fill_result_t CHOICE_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, const asn_encoding_constraints_t *constr, size_t max_length)
Definition: constr_CHOICE_rfill.c:10
ATF_POINTER
@ ATF_POINTER
Definition: constr_TYPE.h:268
_set_present_idx
void _set_present_idx(void *sptr, unsigned offset, unsigned size, unsigned present)
Definition: constr_CHOICE.c:236
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
asn_TYPE_member_s::type
asn_TYPE_descriptor_t * type
Definition: constr_TYPE.h:278
asn_random_fill_result_s
Definition: asn_random_fill.h:24
asn_TYPE_descriptor_s::specifics
const void * specifics
Definition: constr_TYPE.h:259
asn_random_between
intmax_t asn_random_between(intmax_t min, intmax_t max)
Definition: asn_random_fill.c:38
asn_TYPE_operation_s::random_fill
asn_random_fill_f * random_fill
Definition: constr_TYPE.h:201
asn_TYPE_descriptor_s::op
asn_TYPE_operation_t * op
Definition: constr_TYPE.h:232
asn_encoding_constraints_s
Definition: constr_TYPE.h:208
asn_internal.h
constr_CHOICE.h
asn_TYPE_member_s
Definition: constr_TYPE.h:272
asn_TYPE_member_s::flags
enum asn_TYPE_flags_e flags
Definition: constr_TYPE.h:273
asn_TYPE_member_s::encoding_constraints
asn_encoding_constraints_t encoding_constraints
Definition: constr_TYPE.h:280


etsi_its_spatem_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:29:28