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)" }
105 external function f_enc_hpt(in HasPardType x) return octetstring
106 with { extension "prototype(convert) encode(JSON)" }
109 external function f_enc_seqofint(in SeqOfInt x) return octetstring
110 with { extension "prototype(convert) encode(JSON)" }
112 external function f_enc_seqprod(in SeqProduct x) return octetstring
113 with { extension "prototype(convert) encode(JSON)" }
115 external function f_enc_number(in Number x) return octetstring
116 with { extension "prototype(convert) encode(JSON)" }
118 external function f_enc_strings(in ManyStrings x) return octetstring
119 with { extension "prototype(convert) encode(JSON)" }
121 external function f_enc_complex(in ComplexSet x) return octetstring
122 with { extension "prototype(convert) encode(JSON)" }
124 external function f_enc_obj(in Object x) return octetstring
125 with { extension "prototype(convert) encode(JSON)" }
127 external function f_enc_null(in HasNull x) return octetstring
128 with { extension "prototype(convert) encode(JSON)" }
130 //=================== Decoders =====================================
133 external function f_dec_int(in octetstring x) return integer
134 with { extension "prototype(convert)"; extension "decode(JSON)"; }
136 external function f_dec_bool(in octetstring x) return boolean
137 with { extension "prototype(convert)"; extension "decode(JSON)"; }
139 external function f_dec_bit(in octetstring x) return bitstring
140 with { extension "prototype(convert)"; extension "decode(JSON)"; }
142 external function f_dec_hex(in octetstring x) return hexstring
143 with { extension "prototype(convert)"; extension "decode(JSON)"; }
145 external function f_dec_f(in octetstring x) return float
146 with { extension "prototype(convert)"; extension "decode(JSON)"; }
148 external function f_dec_days(in octetstring x) return Days
149 with { extension "prototype(convert)"; extension "decode(JSON)"; }
151 external function f_dec_os(in octetstring x) return octetstring
152 with { extension "prototype(convert)"; extension "decode(JSON)"; }
154 external function f_dec_vt(in octetstring x) return verdicttype
155 with { extension "prototype(convert)"; extension "decode(JSON)"; }
157 external function f_dec_cs(in octetstring x) return charstring
158 with { extension "prototype(convert)"; extension "decode(JSON)"; }
160 external function f_dec_cs_x(in octetstring x) return charstring
161 with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; }
163 external function f_dec_ucs(in octetstring x) return universal charstring
164 with { extension "prototype(convert)"; extension "decode(JSON)"; }
166 external function f_dec_ucs_x(in octetstring x) return universal charstring
167 with { extension "prototype(convert)"; extension "decode(XER:XER_EXTENDED)"; }
169 external function f_dec_ints(in octetstring u) return IntArr
170 with { extension "prototype(convert)"; extension "decode(JSON)"; }
172 external function f_dec_floats(in octetstring u) return FloatArr
173 with { extension "prototype(convert)"; extension "decode(JSON)"; }
175 external function f_dec_strs(in octetstring u) return StrArr
176 with { extension "prototype(convert)"; extension "decode(JSON)"; }
178 external function f_dec_R(in octetstring x) return R
179 with { extension "prototype(convert)"; extension "decode(JSON)"; }
181 external function f_dec_A(in octetstring x) return A
182 with { extension "prototype(convert)"; extension "decode(JSON)"; }
184 external function f_dec_ER(in octetstring x) return EmptyRec
185 with { extension "prototype(convert)"; extension "decode(JSON)"; }
187 external function f_dec_roi(in octetstring x) return RoI
188 with { extension "prototype(convert)"; extension "decode(JSON)"; }
190 external function f_dec_rof(in octetstring x) return RoF
191 with { extension "prototype(convert)"; extension "decode(JSON)"; }
193 external function f_dec_rocs(in octetstring x) return RoCS
194 with { extension "prototype(convert)"; extension "decode(JSON)"; }
196 external function f_dec_profile(in octetstring u) return Profile
197 with { extension "prototype(convert)"; extension "decode(JSON)"; }
199 external function f_dec_profile0(in octetstring u) return Profile0
200 with { extension "prototype(convert)"; extension "decode(JSON)"; }
202 external function f_dec_cba(in octetstring u) return CBA
203 with { extension "prototype(convert)"; extension "decode(JSON)"; }
205 external function f_dec_stuff(in octetstring x) return Stuff
206 with { extension "prototype(convert) decode(JSON)" }
208 external function f_dec_def(in octetstring x) return RecDef
209 with { extension "prototype(convert) decode(JSON)" }
211 external function f_dec_hpt(in octetstring x) return HasPardType
212 with { extension "prototype(convert) decode(JSON)" }
215 external function f_dec_seqofint(in octetstring x) return SeqOfInt
216 with { extension "prototype(convert) decode(JSON)" }
218 external function f_dec_seqprod(in octetstring x) return SeqProduct
219 with { extension "prototype(convert) decode(JSON)" }
221 external function f_dec_number(in octetstring x) return Number
222 with { extension "prototype(convert) decode(JSON)" }
224 external function f_dec_strings(in octetstring x) return ManyStrings
225 with { extension "prototype(convert) decode(JSON)" }
227 external function f_dec_complex(in octetstring x) return ComplexSet
228 with { extension "prototype(convert) decode(JSON)" }
230 external function f_dec_obj(in octetstring x) return Object
231 with { extension "prototype(convert) decode(JSON)" }
233 external function f_dec_null(in octetstring x) return HasNull
234 with { extension "prototype(convert) decode(JSON)" }
236 //============== Internal Functions ====================
238 function f_check_encoding(in octetstring encoded, in octetstring expected) {
239 log("encoded: ",encoded," expected: ",expected)
240 if(encoded == expected) {
243 setverdict(fail, "expected:", expected,"received: ", encoded);
245 } with { extension "transparent"}
249 function f_bool2verdict(in boolean b) {
250 if(b){setverdict(pass)} else {setverdict(fail)}
251 } with { extension "transparent"}
253 function f_abs(in float f) return float {
254 if(f < 0.0 ) { f:= -f }