ec984ce51142b8bf0de3dedcd810bf71c5c22347
[com/asn1c.git] / tests / tests-asn1c-compiler / 147-inherit-per-constraints-OK.asn1.-Pgen-OER
1
2 /*** <<< INCLUDES [Short] >>> ***/
3
4 #include <NativeInteger.h>
5
6 /*** <<< TYPE-DECLS [Short] >>> ***/
7
8 typedef long     Short_t;
9
10 /*** <<< FUNC-DECLS [Short] >>> ***/
11
12 extern asn_TYPE_descriptor_t asn_DEF_Short;
13 asn_struct_free_f Short_free;
14 asn_struct_print_f Short_print;
15 asn_constr_check_f Short_constraint;
16 ber_type_decoder_f Short_decode_ber;
17 der_type_encoder_f Short_encode_der;
18 xer_type_decoder_f Short_decode_xer;
19 xer_type_encoder_f Short_encode_xer;
20 oer_type_decoder_f Short_decode_oer;
21 oer_type_encoder_f Short_encode_oer;
22
23 /*** <<< CODE [Short] >>> ***/
24
25 int
26 Short_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
27                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
28         long value;
29         
30         if(!sptr) {
31                 ASN__CTFAIL(app_key, td, sptr,
32                         "%s: value not given (%s:%d)",
33                         td->name, __FILE__, __LINE__);
34                 return -1;
35         }
36         
37         value = *(const long *)sptr;
38         
39         if((value >= 0 && value <= 65535)) {
40                 /* Constraint check succeeded */
41                 return 0;
42         } else {
43                 ASN__CTFAIL(app_key, td, sptr,
44                         "%s: constraint failed (%s:%d)",
45                         td->name, __FILE__, __LINE__);
46                 return -1;
47         }
48 }
49
50 /*
51  * This type is implemented using NativeInteger,
52  * so here we adjust the DEF accordingly.
53  */
54
55 /*** <<< CTDEFS [Short] >>> ***/
56
57 static asn_oer_constraints_t asn_OER_type_Short_constr_1 CC_NOTUSED = {
58         { 2, 1 }        /* (0..65535) */,
59         -1};
60
61 /*** <<< STAT-DEFS [Short] >>> ***/
62
63 static const ber_tlv_tag_t asn_DEF_Short_tags_1[] = {
64         (ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
65 };
66 asn_TYPE_descriptor_t asn_DEF_Short = {
67         "Short",
68         "Short",
69         &asn_OP_NativeInteger,
70         asn_DEF_Short_tags_1,
71         sizeof(asn_DEF_Short_tags_1)
72                 /sizeof(asn_DEF_Short_tags_1[0]), /* 1 */
73         asn_DEF_Short_tags_1,   /* Same as above */
74         sizeof(asn_DEF_Short_tags_1)
75                 /sizeof(asn_DEF_Short_tags_1[0]), /* 1 */
76         { &asn_OER_type_Short_constr_1, 0, Short_constraint },
77         0, 0,   /* No members */
78         0       /* No specifics */
79 };
80
81
82 /*** <<< INCLUDES [Alias] >>> ***/
83
84 #include "Short.h"
85
86 /*** <<< TYPE-DECLS [Alias] >>> ***/
87
88 typedef Short_t  Alias_t;
89
90 /*** <<< FUNC-DECLS [Alias] >>> ***/
91
92 extern asn_TYPE_descriptor_t asn_DEF_Alias;
93 asn_struct_free_f Alias_free;
94 asn_struct_print_f Alias_print;
95 asn_constr_check_f Alias_constraint;
96 ber_type_decoder_f Alias_decode_ber;
97 der_type_encoder_f Alias_encode_der;
98 xer_type_decoder_f Alias_decode_xer;
99 xer_type_encoder_f Alias_encode_xer;
100 oer_type_decoder_f Alias_decode_oer;
101 oer_type_encoder_f Alias_encode_oer;
102
103 /*** <<< CODE [Alias] >>> ***/
104
105 int
106 Alias_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
107                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
108         long value;
109         
110         if(!sptr) {
111                 ASN__CTFAIL(app_key, td, sptr,
112                         "%s: value not given (%s:%d)",
113                         td->name, __FILE__, __LINE__);
114                 return -1;
115         }
116         
117         value = *(const long *)sptr;
118         
119         if((value >= 0 && value <= 65535)) {
120                 /* Constraint check succeeded */
121                 return 0;
122         } else {
123                 ASN__CTFAIL(app_key, td, sptr,
124                         "%s: constraint failed (%s:%d)",
125                         td->name, __FILE__, __LINE__);
126                 return -1;
127         }
128 }
129
130 /*
131  * This type is implemented using Short,
132  * so here we adjust the DEF accordingly.
133  */
134
135 /*** <<< CTDEFS [Alias] >>> ***/
136
137 static asn_oer_constraints_t asn_OER_type_Alias_constr_1 CC_NOTUSED = {
138         { 2, 1 }        /* (0..65535) */,
139         -1};
140
141 /*** <<< STAT-DEFS [Alias] >>> ***/
142
143 static const ber_tlv_tag_t asn_DEF_Alias_tags_1[] = {
144         (ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
145 };
146 asn_TYPE_descriptor_t asn_DEF_Alias = {
147         "Alias",
148         "Alias",
149         &asn_OP_NativeInteger,
150         asn_DEF_Alias_tags_1,
151         sizeof(asn_DEF_Alias_tags_1)
152                 /sizeof(asn_DEF_Alias_tags_1[0]), /* 1 */
153         asn_DEF_Alias_tags_1,   /* Same as above */
154         sizeof(asn_DEF_Alias_tags_1)
155                 /sizeof(asn_DEF_Alias_tags_1[0]), /* 1 */
156         { &asn_OER_type_Alias_constr_1, 0, Alias_constraint },
157         0, 0,   /* No members */
158         0       /* No specifics */
159 };
160
161
162 /*** <<< INCLUDES [Soo] >>> ***/
163
164 #include <NativeInteger.h>
165 #include "Short.h"
166 #include "Alias.h"
167 #include <constr_SEQUENCE.h>
168
169 /*** <<< TYPE-DECLS [Soo] >>> ***/
170
171 typedef struct Soo {
172         long     foo;
173         Short_t  bar;
174         Alias_t  baz;
175         
176         /* Context for parsing across buffer boundaries */
177         asn_struct_ctx_t _asn_ctx;
178 } Soo_t;
179
180 /*** <<< FUNC-DECLS [Soo] >>> ***/
181
182 extern asn_TYPE_descriptor_t asn_DEF_Soo;
183
184 /*** <<< CODE [Soo] >>> ***/
185
186 static int
187 memb_foo_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
188                         asn_app_constraint_failed_f *ctfailcb, void *app_key) {
189         long value;
190         
191         if(!sptr) {
192                 ASN__CTFAIL(app_key, td, sptr,
193                         "%s: value not given (%s:%d)",
194                         td->name, __FILE__, __LINE__);
195                 return -1;
196         }
197         
198         value = *(const long *)sptr;
199         
200         if((value >= 0 && value <= 65535)) {
201                 /* Constraint check succeeded */
202                 return 0;
203         } else {
204                 ASN__CTFAIL(app_key, td, sptr,
205                         "%s: constraint failed (%s:%d)",
206                         td->name, __FILE__, __LINE__);
207                 return -1;
208         }
209 }
210
211
212 /*** <<< CTDEFS [Soo] >>> ***/
213
214 static asn_oer_constraints_t asn_OER_memb_foo_constr_2 CC_NOTUSED = {
215         { 2, 1 }        /* (0..65535) */,
216         -1};
217
218 /*** <<< STAT-DEFS [Soo] >>> ***/
219
220 static asn_TYPE_member_t asn_MBR_Soo_1[] = {
221         { ATF_NOFLAGS, 0, offsetof(struct Soo, foo),
222                 .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
223                 .tag_mode = 0,
224                 .type = &asn_DEF_NativeInteger,
225                 .type_selector = 0,
226                 { .oer_constraints = &asn_OER_memb_foo_constr_2, .per_constraints = 0, .general_constraints =  memb_foo_constraint_1 },
227                 0, 0, /* No default value */
228                 .name = "foo"
229                 },
230         { ATF_NOFLAGS, 0, offsetof(struct Soo, bar),
231                 .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
232                 .tag_mode = 0,
233                 .type = &asn_DEF_Short,
234                 .type_selector = 0,
235                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
236                 0, 0, /* No default value */
237                 .name = "bar"
238                 },
239         { ATF_NOFLAGS, 0, offsetof(struct Soo, baz),
240                 .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
241                 .tag_mode = 0,
242                 .type = &asn_DEF_Alias,
243                 .type_selector = 0,
244                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
245                 0, 0, /* No default value */
246                 .name = "baz"
247                 },
248 };
249 static const ber_tlv_tag_t asn_DEF_Soo_tags_1[] = {
250         (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
251 };
252 static const asn_TYPE_tag2member_t asn_MAP_Soo_tag2el_1[] = {
253     { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 2 }, /* foo */
254     { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 1, -1, 1 }, /* bar */
255     { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 2, -2, 0 } /* baz */
256 };
257 static asn_SEQUENCE_specifics_t asn_SPC_Soo_specs_1 = {
258         sizeof(struct Soo),
259         offsetof(struct Soo, _asn_ctx),
260         .tag2el = asn_MAP_Soo_tag2el_1,
261         .tag2el_count = 3,      /* Count of tags in the map */
262         0, 0, 0,        /* Optional elements (not needed) */
263         -1,     /* First extension addition */
264 };
265 asn_TYPE_descriptor_t asn_DEF_Soo = {
266         "Soo",
267         "Soo",
268         &asn_OP_SEQUENCE,
269         asn_DEF_Soo_tags_1,
270         sizeof(asn_DEF_Soo_tags_1)
271                 /sizeof(asn_DEF_Soo_tags_1[0]), /* 1 */
272         asn_DEF_Soo_tags_1,     /* Same as above */
273         sizeof(asn_DEF_Soo_tags_1)
274                 /sizeof(asn_DEF_Soo_tags_1[0]), /* 1 */
275         { 0, 0, SEQUENCE_constraint },
276         asn_MBR_Soo_1,
277         3,      /* Elements count */
278         &asn_SPC_Soo_specs_1    /* Additional specs */
279 };
280