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 ******************************************************************************/
11 import from Types all;
12 import from JsonData language "ASN.1" all;
14 //=================== Encoders =====================================
17 external function f_enc_int(in integer x) return octetstring
18 with { extension "prototype(convert)"; extension "encode(JSON)"; }
20 external function f_enc_bool(in boolean x) return octetstring
21 with { extension "prototype(convert)"; extension "encode(JSON)"; }
23 external function f_enc_cs(in charstring x) return octetstring
24 with { extension "prototype(convert)"; extension "encode(JSON)"; }
26 external function f_enc_cs_x(in charstring x) return octetstring
27 with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; }
29 external function f_enc_ucs_x(in universal charstring x) return octetstring
30 with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; }
32 external function f_enc_os(in octetstring x) return octetstring
33 with { extension "prototype(convert)"; extension "encode(JSON)"; }
35 external function f_enc_hex(in hexstring x) return octetstring
36 with { extension "prototype(convert)"; extension "encode(JSON)"; }
38 external function f_enc_bit(in bitstring x) return octetstring
39 with { extension "prototype(convert)"; extension "encode(JSON)"; }
41 external function f_enc_vt(in verdicttype x) return octetstring
42 with { extension "prototype(convert)"; extension "encode(JSON)"; }
44 external function f_enc_ucs(in universal charstring x) return octetstring
45 with { extension "prototype(convert)"; extension "encode(JSON)"; }
47 external function f_enc_f(in float x) return octetstring
48 with { extension "prototype(convert)"; extension "encode(JSON)"; }
50 external function f_enc_f_x(in float x) return octetstring
51 with { extension "prototype(convert)"; extension "encode(XER:XER_EXTENDED)"; }
53 external function f_enc_days(in Days x) return octetstring
54 with { extension "prototype(convert)"; extension "encode(JSON)"; }
56 external function f_enc_R(in R rec) return octetstring
57 with { extension "prototype(convert)"; extension "encode(JSON)"; }
59 external function f_enc_A(in A u) return octetstring
60 with { extension "prototype(convert)"; extension "encode(JSON)"; }
62 external function f_enc_ER(in EmptyRec u) return octetstring
63 with { extension "prototype(convert)"; extension "encode(JSON)"; }
66 external function f_enc_roi(in RoI u) return octetstring
67 with { extension "prototype(convert)"; extension "encode(JSON)"; }
69 external function f_enc_rof(in RoF u) return octetstring
70 with { extension "prototype(convert)"; extension "encode(JSON)"; }
72 external function f_enc_rocs(in RoCS u) return octetstring
73 with { extension "prototype(convert)"; extension "encode(JSON)"; }
75 external function f_enc_ints(in IntArr u) return octetstring
76 with { extension "prototype(convert)"; extension "encode(JSON)"; }
78 external function f_enc_floats(in FloatArr u) return octetstring
79 with { extension "prototype(convert)"; extension "encode(JSON)"; }
81 external function f_enc_strs(in StrArr u) return octetstring
82 with { extension "prototype(convert)"; extension "encode(JSON)"; }
84 external function f_enc_profile(in Profile u) return octetstring
85 with { extension "prototype(convert)"; extension "encode(JSON)"; }
87 external function f_enc_profile_compact(in Profile u) return octetstring
88 with { extension "prototype(convert) encode(JSON) printing(compact)"; }
90 external function f_enc_profile_compact_p(in Profile u) return octetstring
91 with { extension "encode(JSON) prototype(convert) printing(compact)"; }
93 external function f_enc_profile_pretty(in Profile u) return octetstring
94 with { extension "prototype(convert) encode(JSON) printing(pretty)"; }
96 external function f_enc_profile0(in Profile0 u) return octetstring
97 with { extension "prototype(convert)"; extension "encode(JSON)"; }
99 external function f_enc_cba(in CBA u) return octetstring
100 with { extension "prototype(convert)"; extension "encode(JSON)"; }
102 external function f_enc_stuff(in Stuff x) return octetstring
103 with { extension "prototype(convert) encode(JSON)" }
106 external function f_enc_seqofint(in SeqOfInt x) return octetstring
107 with { extension "prototype(convert) encode(JSON)" }
109 external function f_enc_seqprod(in SeqProduct x) return octetstring
110 with { extension "prototype(convert) encode(JSON)" }
112 external function f_enc_number(in Number x) return octetstring
113 with { extension "prototype(convert) encode(JSON)" }
115 external function f_enc_strings(in ManyStrings x) return octetstring
116 with { extension "prototype(convert) encode(JSON)" }
118 external function f_enc_complex(in ComplexSet x) return octetstring
119 with { extension "prototype(convert) encode(JSON)" }
121 //=================== Decoders =====================================
124 external function f_dec_int(in octetstring x) return integer
125 with { extension "prototype(convert)"; extension "decode(JSON)"; }
127 external function f_dec_bool(in octetstring x) return boolean
128 with { extension "prototype(convert)"; extension "decode(JSON)"; }
130 external function f_dec_bit(in octetstring x) return bitstring
131 with { extension "prototype(convert)"; extension "decode(JSON)"; }
133 external function f_dec_hex(in octetstring x) return hexstring
134 with { extension "prototype(convert)"; extension "decode(JSON)"; }
136 external function f_dec_f(in octetstring x) return float
137 with { extension "prototype(convert)"; extension "decode(JSON)"; }
139 external function f_dec_days(in octetstring x) return Days
140 with { extension "prototype(convert)"; extension "decode(JSON)"; }
142 external function f_dec_os(in octetstring x) return octetstring
143 with { extension "prototype(convert)"; extension "decode(JSON)"; }
145 external function f_dec_vt(in octetstring x) return verdicttype
146 with { extension "prototype(convert)"; extension "decode(JSON)"; }
148 external function f_dec_cs(in octetstring x) return charstring
149 with { extension "prototype(convert)"; extension "decode(JSON)"; }
151 external function f_dec_cs_x(in octetstring x) return charstring
152 with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; }
154 external function f_dec_ucs(in octetstring x) return universal charstring
155 with { extension "prototype(convert)"; extension "decode(JSON)"; }
157 external function f_dec_ucs_x(in octetstring x) return universal charstring
158 with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; }
160 external function f_dec_ints(in octetstring u) return IntArr
161 with { extension "prototype(convert)"; extension "decode(JSON)"; }
163 external function f_dec_floats(in octetstring u) return FloatArr
164 with { extension "prototype(convert)"; extension "decode(JSON)"; }
166 external function f_dec_strs(in octetstring u) return StrArr
167 with { extension "prototype(convert)"; extension "decode(JSON)"; }
169 external function f_dec_R(in octetstring x) return R
170 with { extension "prototype(convert)"; extension "decode(JSON)"; }
172 external function f_dec_A(in octetstring x) return A
173 with { extension "prototype(convert)"; extension "decode(JSON)"; }
175 external function f_dec_ER(in octetstring x) return EmptyRec
176 with { extension "prototype(convert)"; extension "decode(JSON)"; }
178 external function f_dec_roi(in octetstring x) return RoI
179 with { extension "prototype(convert)"; extension "decode(JSON)"; }
181 external function f_dec_rof(in octetstring x) return RoF
182 with { extension "prototype(convert)"; extension "decode(JSON)"; }
184 external function f_dec_rocs(in octetstring x) return RoCS
185 with { extension "prototype(convert)"; extension "decode(JSON)"; }
187 external function f_dec_profile(in octetstring u) return Profile
188 with { extension "prototype(convert)"; extension "decode(JSON)"; }
190 external function f_dec_profile0(in octetstring u) return Profile0
191 with { extension "prototype(convert)"; extension "decode(JSON)"; }
193 external function f_dec_cba(in octetstring u) return CBA
194 with { extension "prototype(convert)"; extension "decode(JSON)"; }
196 external function f_dec_stuff(in octetstring x) return Stuff
197 with { extension "prototype(convert) decode(JSON)" }
199 external function f_dec_def(in octetstring x) return RecDef
200 with { extension "prototype(convert) decode(JSON)" }
203 external function f_dec_seqofint(in octetstring x) return SeqOfInt
204 with { extension "prototype(convert) decode(JSON)" }
206 external function f_dec_seqprod(in octetstring x) return SeqProduct
207 with { extension "prototype(convert) decode(JSON)" }
209 external function f_dec_number(in octetstring x) return Number
210 with { extension "prototype(convert) decode(JSON)" }
212 external function f_dec_strings(in octetstring x) return ManyStrings
213 with { extension "prototype(convert) decode(JSON)" }
215 external function f_dec_complex(in octetstring x) return ComplexSet
216 with { extension "prototype(convert) decode(JSON)" }
218 //============== Internal Functions ====================
220 function f_check_encoding(in octetstring encoded, in octetstring expected) {
221 log("encoded: ",encoded," expected: ",expected)
222 if(encoded == expected) {
225 setverdict(fail, "expected:", expected,"received: ", encoded);
227 } with { extension "transparent"}
231 function f_bool2verdict(in boolean b) {
232 if(b){setverdict(pass)} else {setverdict(fail)}
233 } with { extension "transparent"}
235 function f_abs(in float f) return float {
236 if(f < 0.0 ) { f:= -f }