2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <constr_SEQUENCE_OF.h>
8 #include <asn_SEQUENCE_OF.h>
11 SEQUENCE_OF_encode_aper(const asn_TYPE_descriptor_t *td,
12 const asn_per_constraints_t *constraints,
13 const void *sptr, asn_per_outp_t *po) {
14 const asn_anonymous_sequence_ *list;
15 const asn_per_constraint_t *ct;
16 asn_enc_rval_t er = {0,0,0};
17 asn_TYPE_member_t *elm = td->elements;
20 if(!sptr) ASN__ENCODE_FAILED;
21 list = _A_CSEQUENCE_FROM_VOID(sptr);
25 ASN_DEBUG("Encoding %s as SEQUENCE OF size (%d) using ALIGNED PER", td->name, list->count);
27 if(constraints) ct = &constraints->size;
28 else if(td->encoding_constraints.per_constraints)
29 ct = &td->encoding_constraints.per_constraints->size;
32 /* If extensible constraint, check if size is in root */
34 int not_in_root = (list->count < ct->lower_bound
35 || list->count > ct->upper_bound);
36 ASN_DEBUG("lb %lld ub %lld %s",
37 (long long int)ct->lower_bound,
38 (long long int)ct->upper_bound,
39 ct->flags & APC_EXTENSIBLE ? "ext" : "fix");
40 if(ct->flags & APC_EXTENSIBLE) {
41 /* Declare whether size is in extension root */
42 if(per_put_few_bits(po, not_in_root, 1))
44 if(not_in_root) ct = 0;
45 } else if(not_in_root && ct->effective_bits >= 0)
49 if(ct && ct->effective_bits >= 0) {
50 /* X.691, #19.5: No length determinant */
52 if(per_put_few_bits(po, list->count - ct->lower_bound,
56 if (ct->lower_bound == ct->upper_bound && ct->upper_bound < 65536) {
57 /* No length determinant */
58 } else if (aper_put_length(po, ct->lower_bound, ct->upper_bound, list->count - ct->lower_bound, 0) < 0)
62 for(seq = -1; seq < list->count;) {
66 if(ct && ct->effective_bits >= 0) {
67 mayEncode = list->count;
69 mayEncode = aper_put_length(po, -1, -1, list->count - seq, &need_eom);
70 if(mayEncode < 0) ASN__ENCODE_FAILED;
74 void *memb_ptr = list->array[seq++];
75 if(!memb_ptr) ASN__ENCODE_FAILED;
76 er = elm->type->op->aper_encoder(elm->type,
77 elm->encoding_constraints.per_constraints,
83 if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0))
84 ASN__ENCODE_FAILED; /* End of Message length */