constr_SEQUENCE_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_SEQUENCE_specifics_t *specs =
15  asn_random_fill_result_t result_ok = {ARFILL_OK, 0};
16  asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
17  asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
18  void *st = *sptr;
19  size_t edx;
20 
21  if(max_length == 0) return result_skipped;
22 
23  (void)constr;
24 
25  if(st == NULL) {
26  st = CALLOC(1, specs->struct_size);
27  if(st == NULL) {
28  return result_failed;
29  }
30  }
31 
32  for(edx = 0; edx < td->elements_count; edx++) {
33  const asn_TYPE_member_t *elm = &td->elements[edx];
34  void *memb_ptr; /* Pointer to the member */
35  void **memb_ptr2; /* Pointer to that pointer */
37 
38  if(elm->optional && asn_random_between(0, 4) == 2) {
39  /* Sometimes decide not to fill the optional value */
40  continue;
41  }
42 
43  if(elm->flags & ATF_POINTER) {
44  /* Member is a pointer to another structure */
45  memb_ptr2 = (void **)((char *)st + elm->memb_offset);
46  } else {
47  memb_ptr = (char *)st + elm->memb_offset;
48  memb_ptr2 = &memb_ptr;
49  }
50 
51  tmpres = elm->type->op->random_fill(
52  elm->type, memb_ptr2, &elm->encoding_constraints,
53  max_length > result_ok.length ? max_length - result_ok.length : 0);
54  switch(tmpres.code) {
55  case ARFILL_OK:
56  result_ok.length += tmpres.length;
57  continue;
58  case ARFILL_SKIPPED:
59  assert(!(elm->flags & ATF_POINTER) || *memb_ptr2 == NULL);
60  continue;
61  case ARFILL_FAILED:
62  if(st == *sptr) {
63  ASN_STRUCT_RESET(*td, st);
64  } else {
65  ASN_STRUCT_FREE(*td, st);
66  }
67  return tmpres;
68  }
69  }
70 
71  *sptr = st;
72 
73  return result_ok;
74 }
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
asn_random_fill_result_s::code
enum asn_random_fill_result_s::@3 code
CALLOC
#define CALLOC(nmemb, size)
Definition: asn_internal.h:37
asn_random_fill_result_s::length
size_t length
Definition: asn_random_fill.h:30
ASN_STRUCT_RESET
#define ASN_STRUCT_RESET(asn_DEF, ptr)
Definition: constr_TYPE.h:112
ATF_POINTER
@ ATF_POINTER
Definition: constr_TYPE.h:268
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_SEQUENCE_specifics_s
Definition: constr_SEQUENCE.h:14
asn_internal.h
SEQUENCE_random_fill
asn_random_fill_result_t SEQUENCE_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, const asn_encoding_constraints_t *constr, size_t max_length)
Definition: constr_SEQUENCE_rfill.c:10
constr_SEQUENCE.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
asn_TYPE_member_s::optional
unsigned optional
Definition: constr_TYPE.h:274


etsi_its_vam_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:30:55