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_uper(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 const 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 (%d)", 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 */
35 (list->count < ct->lower_bound || list->count > ct->upper_bound);
36 ASN_DEBUG("lb %ld ub %ld %s", ct->lower_bound, ct->upper_bound,
37 ct->flags & APC_EXTENSIBLE ? "ext" : "fix");
38 if(ct->flags & APC_EXTENSIBLE) {
39 /* Declare whether size is in extension root */
40 if(per_put_few_bits(po, not_in_root, 1)) ASN__ENCODE_FAILED;
41 if(not_in_root) ct = 0;
42 } else if(not_in_root && ct->effective_bits >= 0) {
48 if(ct && ct->effective_bits >= 0) {
49 /* X.691, #19.5: No length determinant */
50 if(per_put_few_bits(po, list->count - ct->lower_bound,
53 } else if(list->count == 0) {
54 /* When the list is empty add only the length determinant
55 * X.691, #20.6 and #11.9.4.1
57 if (uper_put_length(po, 0, 0)) {
63 for(encoded_edx = 0; (ssize_t)encoded_edx < list->count;) {
68 if(ct && ct->effective_bits >= 0) {
69 may_encode = list->count;
72 uper_put_length(po, list->count - encoded_edx, &need_eom);
73 if(may_encode < 0) ASN__ENCODE_FAILED;
76 for(edx = encoded_edx; edx < encoded_edx + may_encode; edx++) {
77 void *memb_ptr = list->array[edx];
78 if(!memb_ptr) ASN__ENCODE_FAILED;
79 er = elm->type->op->uper_encoder(
80 elm->type, elm->encoding_constraints.per_constraints, memb_ptr,
82 if(er.encoded == -1) ASN__ENCODE_FAILED;
85 if(need_eom && uper_put_length(po, 0, 0))
86 ASN__ENCODE_FAILED; /* End of Message length */
88 encoded_edx += may_encode;