Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
3abe9331 | 2 | * Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | ******************************************************************************/ | |
8 | module Functions | |
9 | { | |
10 | ||
11 | import from Types all; | |
12 | import from JsonData language "ASN.1" all; | |
13 | ||
14 | //=================== Encoders ===================================== | |
15 | ||
16 | // for TTCN-3 types | |
17 | external function f_enc_int(in integer x) return octetstring | |
18 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
19 | ||
20 | external function f_enc_bool(in boolean x) return octetstring | |
21 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
22 | ||
23 | external function f_enc_cs(in charstring x) return octetstring | |
24 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
25 | ||
26 | external function f_enc_cs_x(in charstring x) return octetstring | |
27 | with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; } | |
28 | ||
29 | external function f_enc_ucs_x(in universal charstring x) return octetstring | |
30 | with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; } | |
31 | ||
32 | external function f_enc_os(in octetstring x) return octetstring | |
33 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
34 | ||
35 | external function f_enc_hex(in hexstring x) return octetstring | |
36 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
37 | ||
38 | external function f_enc_bit(in bitstring x) return octetstring | |
39 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
40 | ||
41 | external function f_enc_vt(in verdicttype x) return octetstring | |
42 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
43 | ||
44 | external function f_enc_ucs(in universal charstring x) return octetstring | |
45 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
46 | ||
47 | external function f_enc_f(in float x) return octetstring | |
48 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
49 | ||
50 | external function f_enc_f_x(in float x) return octetstring | |
51 | with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; } | |
52 | ||
53 | external function f_enc_days(in Days x) return octetstring | |
54 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
55 | ||
56 | external function f_enc_R(in R rec) return octetstring | |
57 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
58 | ||
59 | external function f_enc_A(in A u) return octetstring | |
60 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
61 | ||
62 | external function f_enc_ER(in EmptyRec u) return octetstring | |
63 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
64 | ||
970ed795 EL |
65 | external function f_enc_roi(in RoI u) return octetstring |
66 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
67 | ||
68 | external function f_enc_rof(in RoF u) return octetstring | |
69 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
70 | ||
71 | external function f_enc_rocs(in RoCS u) return octetstring | |
72 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
73 | ||
74 | external function f_enc_ints(in IntArr u) return octetstring | |
75 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
76 | ||
77 | external function f_enc_floats(in FloatArr u) return octetstring | |
78 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
79 | ||
80 | external function f_enc_strs(in StrArr u) return octetstring | |
81 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
82 | ||
83 | external function f_enc_profile(in Profile u) return octetstring | |
84 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
85 | ||
86 | external function f_enc_profile_compact(in Profile u) return octetstring | |
87 | with { extension "prototype(convert) encode(JSON) printing(compact)"; } | |
88 | ||
89 | external function f_enc_profile_compact_p(in Profile u) return octetstring | |
90 | with { extension "encode(JSON) prototype(convert) printing(compact)"; } | |
91 | ||
92 | external function f_enc_profile_pretty(in Profile u) return octetstring | |
93 | with { extension "prototype(convert) encode(JSON) printing(pretty)"; } | |
94 | ||
95 | external function f_enc_profile0(in Profile0 u) return octetstring | |
96 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
97 | ||
98 | external function f_enc_cba(in CBA u) return octetstring | |
99 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
100 | ||
101 | external function f_enc_stuff(in Stuff x) return octetstring | |
102 | with { extension "prototype(convert) encode(JSON)" } | |
103 | ||
af710487 | 104 | external function f_enc_hpt(in HasPardType x) return octetstring |
105 | with { extension "prototype(convert) encode(JSON)" } | |
106 | ||
3abe9331 | 107 | external function f_enc_asn_stuff(in AsnStuff x) return octetstring |
108 | with { extension "prototype(convert) encode(JSON)" } | |
109 | ||
110 | external function f_enc_opt_uni(in OptionalUnions x) return octetstring | |
111 | with { extension "prototype(convert) encode(JSON)" } | |
112 | ||
113 | external function f_enc_meta_rec(in MetainfoRecord x) return octetstring | |
114 | with { extension "prototype(convert) encode(JSON)" } | |
115 | ||
116 | external function f_enc_meta_set(in MetainfoSet x) return octetstring | |
117 | with { extension "prototype(convert) encode(JSON)" } | |
118 | ||
970ed795 EL |
119 | // for ASN.1 types |
120 | external function f_enc_seqofint(in SeqOfInt x) return octetstring | |
121 | with { extension "prototype(convert) encode(JSON)" } | |
122 | ||
123 | external function f_enc_seqprod(in SeqProduct x) return octetstring | |
124 | with { extension "prototype(convert) encode(JSON)" } | |
125 | ||
126 | external function f_enc_number(in Number x) return octetstring | |
127 | with { extension "prototype(convert) encode(JSON)" } | |
128 | ||
129 | external function f_enc_strings(in ManyStrings x) return octetstring | |
130 | with { extension "prototype(convert) encode(JSON)" } | |
131 | ||
132 | external function f_enc_complex(in ComplexSet x) return octetstring | |
133 | with { extension "prototype(convert) encode(JSON)" } | |
af710487 | 134 | |
135 | external function f_enc_obj(in Object x) return octetstring | |
136 | with { extension "prototype(convert) encode(JSON)" } | |
137 | ||
138 | external function f_enc_null(in HasNull x) return octetstring | |
139 | with { extension "prototype(convert) encode(JSON)" } | |
970ed795 EL |
140 | |
141 | //=================== Decoders ===================================== | |
142 | ||
143 | // for TTCN-3 types | |
144 | external function f_dec_int(in octetstring x) return integer | |
145 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
146 | ||
147 | external function f_dec_bool(in octetstring x) return boolean | |
148 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
149 | ||
150 | external function f_dec_bit(in octetstring x) return bitstring | |
151 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
152 | ||
153 | external function f_dec_hex(in octetstring x) return hexstring | |
154 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
155 | ||
156 | external function f_dec_f(in octetstring x) return float | |
157 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
158 | ||
159 | external function f_dec_days(in octetstring x) return Days | |
160 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
161 | ||
162 | external function f_dec_os(in octetstring x) return octetstring | |
163 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
164 | ||
165 | external function f_dec_vt(in octetstring x) return verdicttype | |
166 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
167 | ||
168 | external function f_dec_cs(in octetstring x) return charstring | |
169 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
170 | ||
171 | external function f_dec_cs_x(in octetstring x) return charstring | |
172 | with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; } | |
173 | ||
174 | external function f_dec_ucs(in octetstring x) return universal charstring | |
175 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
176 | ||
177 | external function f_dec_ucs_x(in octetstring x) return universal charstring | |
178 | with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; } | |
179 | ||
180 | external function f_dec_ints(in octetstring u) return IntArr | |
181 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
182 | ||
183 | external function f_dec_floats(in octetstring u) return FloatArr | |
184 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
185 | ||
186 | external function f_dec_strs(in octetstring u) return StrArr | |
187 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
188 | ||
189 | external function f_dec_R(in octetstring x) return R | |
190 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
191 | ||
192 | external function f_dec_A(in octetstring x) return A | |
193 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
194 | ||
195 | external function f_dec_ER(in octetstring x) return EmptyRec | |
196 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
197 | ||
198 | external function f_dec_roi(in octetstring x) return RoI | |
199 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
200 | ||
201 | external function f_dec_rof(in octetstring x) return RoF | |
202 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
203 | ||
204 | external function f_dec_rocs(in octetstring x) return RoCS | |
205 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
206 | ||
207 | external function f_dec_profile(in octetstring u) return Profile | |
208 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
209 | ||
210 | external function f_dec_profile0(in octetstring u) return Profile0 | |
211 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
212 | ||
213 | external function f_dec_cba(in octetstring u) return CBA | |
214 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
215 | ||
216 | external function f_dec_stuff(in octetstring x) return Stuff | |
217 | with { extension "prototype(convert) decode(JSON)" } | |
218 | ||
219 | external function f_dec_def(in octetstring x) return RecDef | |
220 | with { extension "prototype(convert) decode(JSON)" } | |
221 | ||
af710487 | 222 | external function f_dec_hpt(in octetstring x) return HasPardType |
223 | with { extension "prototype(convert) decode(JSON)" } | |
224 | ||
3abe9331 | 225 | external function f_dec_asn_stuff(in octetstring x) return AsnStuff |
226 | with { extension "prototype(convert) decode(JSON)" } | |
227 | ||
228 | external function f_dec_opt_uni(in octetstring x) return OptionalUnions | |
229 | with { extension "prototype(convert) decode(JSON)" } | |
230 | ||
231 | external function f_dec_meta_rec(in octetstring x) return MetainfoRecord | |
232 | with { extension "prototype(convert) decode(JSON)" } | |
233 | ||
234 | external function f_dec_meta_set(in octetstring x) return MetainfoSet | |
235 | with { extension "prototype(convert) decode(JSON)" } | |
236 | ||
970ed795 EL |
237 | // for ASN.1 types |
238 | external function f_dec_seqofint(in octetstring x) return SeqOfInt | |
239 | with { extension "prototype(convert) decode(JSON)" } | |
240 | ||
241 | external function f_dec_seqprod(in octetstring x) return SeqProduct | |
242 | with { extension "prototype(convert) decode(JSON)" } | |
243 | ||
244 | external function f_dec_number(in octetstring x) return Number | |
245 | with { extension "prototype(convert) decode(JSON)" } | |
246 | ||
247 | external function f_dec_strings(in octetstring x) return ManyStrings | |
248 | with { extension "prototype(convert) decode(JSON)" } | |
249 | ||
250 | external function f_dec_complex(in octetstring x) return ComplexSet | |
251 | with { extension "prototype(convert) decode(JSON)" } | |
af710487 | 252 | |
253 | external function f_dec_obj(in octetstring x) return Object | |
254 | with { extension "prototype(convert) decode(JSON)" } | |
255 | ||
256 | external function f_dec_null(in octetstring x) return HasNull | |
257 | with { extension "prototype(convert) decode(JSON)" } | |
970ed795 EL |
258 | |
259 | //============== Internal Functions ==================== | |
260 | ||
261 | function f_check_encoding(in octetstring encoded, in octetstring expected) { | |
262 | log("encoded: ",encoded," expected: ",expected) | |
263 | if(encoded == expected) { | |
264 | setverdict(pass); | |
265 | } else { | |
266 | setverdict(fail, "expected:", expected,"received: ", encoded); | |
267 | } | |
268 | } with { extension "transparent"} | |
269 | ||
270 | ||
271 | ||
272 | function f_bool2verdict(in boolean b) { | |
273 | if(b){setverdict(pass)} else {setverdict(fail)} | |
274 | } with { extension "transparent"} | |
275 | ||
276 | function f_abs(in float f) return float { | |
277 | if(f < 0.0 ) { f:= -f } | |
278 | return f; | |
279 | } | |
280 | ||
281 | } |