Commit | Line | Data |
---|---|---|
970ed795 EL |
1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2014 Ericsson Telecom AB | |
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 | ||
65 | ||
66 | external function f_enc_roi(in RoI u) return octetstring | |
67 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
68 | ||
69 | external function f_enc_rof(in RoF u) return octetstring | |
70 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
71 | ||
72 | external function f_enc_rocs(in RoCS u) return octetstring | |
73 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
74 | ||
75 | external function f_enc_ints(in IntArr u) return octetstring | |
76 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
77 | ||
78 | external function f_enc_floats(in FloatArr u) return octetstring | |
79 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
80 | ||
81 | external function f_enc_strs(in StrArr u) return octetstring | |
82 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
83 | ||
84 | external function f_enc_profile(in Profile u) return octetstring | |
85 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
86 | ||
87 | external function f_enc_profile_compact(in Profile u) return octetstring | |
88 | with { extension "prototype(convert) encode(JSON) printing(compact)"; } | |
89 | ||
90 | external function f_enc_profile_compact_p(in Profile u) return octetstring | |
91 | with { extension "encode(JSON) prototype(convert) printing(compact)"; } | |
92 | ||
93 | external function f_enc_profile_pretty(in Profile u) return octetstring | |
94 | with { extension "prototype(convert) encode(JSON) printing(pretty)"; } | |
95 | ||
96 | external function f_enc_profile0(in Profile0 u) return octetstring | |
97 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
98 | ||
99 | external function f_enc_cba(in CBA u) return octetstring | |
100 | with { extension "prototype(convert)"; extension "encode(JSON)"; } | |
101 | ||
102 | external function f_enc_stuff(in Stuff x) return octetstring | |
103 | with { extension "prototype(convert) encode(JSON)" } | |
104 | ||
af710487 | 105 | external function f_enc_hpt(in HasPardType x) return octetstring |
106 | with { extension "prototype(convert) encode(JSON)" } | |
107 | ||
970ed795 EL |
108 | // for ASN.1 types |
109 | external function f_enc_seqofint(in SeqOfInt x) return octetstring | |
110 | with { extension "prototype(convert) encode(JSON)" } | |
111 | ||
112 | external function f_enc_seqprod(in SeqProduct x) return octetstring | |
113 | with { extension "prototype(convert) encode(JSON)" } | |
114 | ||
115 | external function f_enc_number(in Number x) return octetstring | |
116 | with { extension "prototype(convert) encode(JSON)" } | |
117 | ||
118 | external function f_enc_strings(in ManyStrings x) return octetstring | |
119 | with { extension "prototype(convert) encode(JSON)" } | |
120 | ||
121 | external function f_enc_complex(in ComplexSet x) return octetstring | |
122 | with { extension "prototype(convert) encode(JSON)" } | |
af710487 | 123 | |
124 | external function f_enc_obj(in Object x) return octetstring | |
125 | with { extension "prototype(convert) encode(JSON)" } | |
126 | ||
127 | external function f_enc_null(in HasNull x) return octetstring | |
128 | with { extension "prototype(convert) encode(JSON)" } | |
970ed795 EL |
129 | |
130 | //=================== Decoders ===================================== | |
131 | ||
132 | // for TTCN-3 types | |
133 | external function f_dec_int(in octetstring x) return integer | |
134 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
135 | ||
136 | external function f_dec_bool(in octetstring x) return boolean | |
137 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
138 | ||
139 | external function f_dec_bit(in octetstring x) return bitstring | |
140 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
141 | ||
142 | external function f_dec_hex(in octetstring x) return hexstring | |
143 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
144 | ||
145 | external function f_dec_f(in octetstring x) return float | |
146 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
147 | ||
148 | external function f_dec_days(in octetstring x) return Days | |
149 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
150 | ||
151 | external function f_dec_os(in octetstring x) return octetstring | |
152 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
153 | ||
154 | external function f_dec_vt(in octetstring x) return verdicttype | |
155 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
156 | ||
157 | external function f_dec_cs(in octetstring x) return charstring | |
158 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
159 | ||
160 | external function f_dec_cs_x(in octetstring x) return charstring | |
161 | with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; } | |
162 | ||
163 | external function f_dec_ucs(in octetstring x) return universal charstring | |
164 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
165 | ||
166 | external function f_dec_ucs_x(in octetstring x) return universal charstring | |
167 | with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; } | |
168 | ||
169 | external function f_dec_ints(in octetstring u) return IntArr | |
170 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
171 | ||
172 | external function f_dec_floats(in octetstring u) return FloatArr | |
173 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
174 | ||
175 | external function f_dec_strs(in octetstring u) return StrArr | |
176 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
177 | ||
178 | external function f_dec_R(in octetstring x) return R | |
179 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
180 | ||
181 | external function f_dec_A(in octetstring x) return A | |
182 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
183 | ||
184 | external function f_dec_ER(in octetstring x) return EmptyRec | |
185 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
186 | ||
187 | external function f_dec_roi(in octetstring x) return RoI | |
188 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
189 | ||
190 | external function f_dec_rof(in octetstring x) return RoF | |
191 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
192 | ||
193 | external function f_dec_rocs(in octetstring x) return RoCS | |
194 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
195 | ||
196 | external function f_dec_profile(in octetstring u) return Profile | |
197 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
198 | ||
199 | external function f_dec_profile0(in octetstring u) return Profile0 | |
200 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
201 | ||
202 | external function f_dec_cba(in octetstring u) return CBA | |
203 | with { extension "prototype(convert)"; extension "decode(JSON)"; } | |
204 | ||
205 | external function f_dec_stuff(in octetstring x) return Stuff | |
206 | with { extension "prototype(convert) decode(JSON)" } | |
207 | ||
208 | external function f_dec_def(in octetstring x) return RecDef | |
209 | with { extension "prototype(convert) decode(JSON)" } | |
210 | ||
af710487 | 211 | external function f_dec_hpt(in octetstring x) return HasPardType |
212 | with { extension "prototype(convert) decode(JSON)" } | |
213 | ||
970ed795 EL |
214 | // for ASN.1 types |
215 | external function f_dec_seqofint(in octetstring x) return SeqOfInt | |
216 | with { extension "prototype(convert) decode(JSON)" } | |
217 | ||
218 | external function f_dec_seqprod(in octetstring x) return SeqProduct | |
219 | with { extension "prototype(convert) decode(JSON)" } | |
220 | ||
221 | external function f_dec_number(in octetstring x) return Number | |
222 | with { extension "prototype(convert) decode(JSON)" } | |
223 | ||
224 | external function f_dec_strings(in octetstring x) return ManyStrings | |
225 | with { extension "prototype(convert) decode(JSON)" } | |
226 | ||
227 | external function f_dec_complex(in octetstring x) return ComplexSet | |
228 | with { extension "prototype(convert) decode(JSON)" } | |
af710487 | 229 | |
230 | external function f_dec_obj(in octetstring x) return Object | |
231 | with { extension "prototype(convert) decode(JSON)" } | |
232 | ||
233 | external function f_dec_null(in octetstring x) return HasNull | |
234 | with { extension "prototype(convert) decode(JSON)" } | |
970ed795 EL |
235 | |
236 | //============== Internal Functions ==================== | |
237 | ||
238 | function f_check_encoding(in octetstring encoded, in octetstring expected) { | |
239 | log("encoded: ",encoded," expected: ",expected) | |
240 | if(encoded == expected) { | |
241 | setverdict(pass); | |
242 | } else { | |
243 | setverdict(fail, "expected:", expected,"received: ", encoded); | |
244 | } | |
245 | } with { extension "transparent"} | |
246 | ||
247 | ||
248 | ||
249 | function f_bool2verdict(in boolean b) { | |
250 | if(b){setverdict(pass)} else {setverdict(fail)} | |
251 | } with { extension "transparent"} | |
252 | ||
253 | function f_abs(in float f) return float { | |
254 | if(f < 0.0 ) { f:= -f } | |
255 | return f; | |
256 | } | |
257 | ||
258 | } |