Use LTTngUSTLogger logger plugin in logtest regression test
[deliverable/titan.core.git] / core / RAW.hh
1 /******************************************************************************
2 * Copyright (c) 2000-2016 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 * Contributors:
9 * Balasko, Jeno
10 * Baranyi, Botond
11 * Forstner, Matyas
12 * Kovacs, Ferenc
13 * Raduly, Csaba
14 * Szabo, Janos Zoltan – initial implementation
15 * Szalai, Gabor
16 *
17 ******************************************************************************/
18 #ifndef _RAW_HH
19 #define _RAW_HH
20
21 #include "Types.h"
22 #include "Encdec.hh"
23
24 struct bignum_st;
25 typedef bignum_st BIGNUM;
26
27 #define RAW_INT_ENC_LENGTH 4
28 #define REVERSE_BITS(b) (BitReverseTable[(b)&0xFF])
29
30 #define RAW_INTX -1
31
32 /**
33 * \defgroup RAW RAW-related stuff.
34 *
35 * The RAW encoder/decoder can be used to handle protocols where the position
36 * of information elements must be specified with bit-level precision.
37 *
38 * @{
39 *
40 * The RAW encoder is a two-pass encoder. In the first pass, information about
41 * all the information elements is collected in a RAW_enc_tree object.
42 * This information is used to write the actual encoding into the buffer.
43 *
44 * This two-pass mechanism is needed because the contents of earlier fields
45 * can depend on fields which have not been encoded yet (e.g. length or
46 * CROSSTAG selector fields).
47 */
48
49 extern const unsigned char BitReverseTable[256];
50 extern const unsigned char BitMaskTable[9];
51 class RAW_enc_tree;
52 struct TTCN_Typedescriptor_t;
53 struct TTCN_TEXTdescriptor_t;
54 int min_bits(int a);
55 int min_bits(BIGNUM *a);
56 enum ext_bit_t{
57 EXT_BIT_NO, /**< No extension bit */
58 EXT_BIT_YES, /**< Extension bit used 0: more octets, 1: no more octets */
59 EXT_BIT_REVERSE /**< Extension bit used 1: more octets, 0: no more octets */
60 };
61 enum top_bit_order_t{
62 TOP_BIT_INHERITED,
63 TOP_BIT_LEFT,
64 TOP_BIT_RIGHT
65 };
66 enum raw_sign_t{
67 SG_NO, /**< no sign, value coded as positive number */
68 SG_2COMPL, /**< the value coded as 2s complement */
69 SG_SG_BIT /**< the MSB used to encode the sign of the value */
70 };
71 /** position indicator of the encoding tree
72 */
73 struct RAW_enc_tr_pos{
74 int level;
75 int *pos;
76 };
77
78 struct RAW_enc_pointer{
79 RAW_enc_tr_pos target;
80 int ptr_offset;
81 int unit;
82 int ptr_base;
83 };
84
85 struct RAW_enc_lengthto{
86 int num_of_fields;
87 RAW_enc_tr_pos* fields;
88 int unit;
89 };
90
91 struct RAW_coding_par{
92 raw_order_t bitorder;
93 raw_order_t byteorder;
94 raw_order_t hexorder;
95 raw_order_t fieldorder;
96 };
97
98 /** RAW attributes for runtime */
99 struct TTCN_RAWdescriptor_t{
100 int fieldlength; /**< length of field in \a unit s */
101 raw_sign_t comp; /**< the method used for storing negative numbers */
102 raw_order_t byteorder;
103 raw_order_t endianness;
104 raw_order_t bitorderinfield;
105 raw_order_t bitorderinoctet;
106 ext_bit_t extension_bit; /**< MSB mangling */
107 raw_order_t hexorder;
108 raw_order_t fieldorder;
109 top_bit_order_t top_bit_order;
110 int padding;
111 int prepadding;
112 int ptroffset;
113 int unit; /**< number of bits per unit */
114 int padding_pattern_length;
115 const unsigned char* padding_pattern;
116 int length_restrition;
117 };
118
119 enum calc_type {
120 CALC_NO, /**< not a calculated field */
121 CALC_LENGTH, /**< calculated field for LENGTHTO */
122 CALC_POINTER /**< calculated field for POINTERTO */
123 };
124
125 /** RAW encoding tree class.
126 * Collects the result of RAW encoding each component, recursively.
127 * */
128 class RAW_enc_tree{
129 public:
130 /** indicates that the node is leaf (contains actual data) or not
131 * (contains pointers to other nodes) */
132 bool isleaf;
133 bool must_free; /**< data_ptr was allocated, must be freed */
134 bool data_ptr_used; /**< Whether data_ptr member is used, not data_array */
135 bool rec_of;
136 RAW_enc_tree *parent;
137 RAW_enc_tr_pos curr_pos;
138 int length; /**< Encoded length */
139 /** @name Encoding parameters related to the filling of the buffer @{ */
140 int padding;
141 int prepadding;
142 int startpos;
143 int padlength;
144 int prepadlength;
145 int padding_pattern_length;
146 const unsigned char* padding_pattern;
147 int align; /**< alignment length */
148 /** @} */
149 int ext_bit_handling; /**< 1: start, 2: stop, 3: only this */
150 ext_bit_t ext_bit;
151 top_bit_order_t top_bit_order;
152 const TTCN_Typedescriptor_t *coding_descr;
153 calc_type calc; /**< is it a calculated field or not */
154 RAW_coding_par coding_par;
155 union{ /** depends on calc */
156 RAW_enc_lengthto lengthto; /**< calc is CALC_LENGTH */
157 RAW_enc_pointer pointerto; /**< calc is CALC_POINTER */
158 } calcof;
159 union{ /** depends on isleaf */
160 struct{
161 int num_of_nodes;
162 RAW_enc_tree **nodes;
163 } node; /**< isleaf is FALSE */
164 /** depends on data_ptr_used */
165 union{
166 unsigned char *data_ptr; /**< data_ptr_used==true */
167 unsigned char data_array[RAW_INT_ENC_LENGTH]; /**< false */
168 } leaf; /**< isleaf is TRUE */
169 } body;
170 RAW_enc_tree(boolean is_leaf, RAW_enc_tree *par, RAW_enc_tr_pos *par_pos,
171 int my_pos,const TTCN_RAWdescriptor_t *raw_attr);
172 ~RAW_enc_tree();
173
174 /** Transfers the encoded information to the buffer.
175 * @param buf buffer to receive the encoded data.
176 * Calls calc_padding, calc_fields and fill_buf.
177 */
178 void put_to_buf(TTCN_Buffer &buf);
179 RAW_enc_tree* get_node(RAW_enc_tr_pos&);
180 private:
181 void fill_buf(TTCN_Buffer &);
182 int calc_padding(int);
183 void calc_fields();
184 /// Copy constructor disabled
185 RAW_enc_tree(const RAW_enc_tree&);
186 /// Assignment disabled
187 RAW_enc_tree& operator=(const RAW_enc_tree&);
188 };
189 struct TTCN_Typedescriptor_t;
190 int RAW_encode_enum_type(const TTCN_Typedescriptor_t&, RAW_enc_tree&,
191 int, int);
192 int RAW_decode_enum_type(const TTCN_Typedescriptor_t&,
193 TTCN_Buffer&, int, raw_order_t, int&,
194 int, bool no_err=false);
195
196 /// Allocate \p nodes_num pointers
197 RAW_enc_tree** init_nodes_of_enc_tree(int nodes_num);
198 /// Allocate \p num structures
199 RAW_enc_tr_pos* init_lengthto_fields_list(int num);
200 int* init_new_tree_pos(RAW_enc_tr_pos &old_pos,int new_levels, int* new_pos);
201 void free_tree_pos(int* ptr);
202 int min_of_ints(int num_of_int, ...);
203
204 extern const TTCN_RAWdescriptor_t INTEGER_raw_;
205 extern const TTCN_RAWdescriptor_t BOOLEAN_raw_;
206 extern const TTCN_RAWdescriptor_t BITSTRING_raw_;
207 extern const TTCN_RAWdescriptor_t OCTETSTRING_raw_;
208 extern const TTCN_RAWdescriptor_t CHARSTRING_raw_;
209 extern const TTCN_RAWdescriptor_t HEXSTRING_raw_;
210 extern const TTCN_RAWdescriptor_t FLOAT_raw_;
211 extern const TTCN_RAWdescriptor_t UNIVERSAL_CHARSTRING_raw_;
212
213 /** @} end of RAW group */
214
215 inline int bigger(int l, int r) {
216 return l < r ? r: l;
217 }
218
219 inline int smaller(int l, int r) {
220 return l < r ? l : r;
221 }
222
223
224 #endif // _RAW_HH
This page took 0.068022 seconds and 5 git commands to generate.